Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A ArduinoJson
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 24
    • Issues 24
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Benoît Blanchon
  • ArduinoJson
  • Issues
  • #1498
Closed
Open
Issue created Feb 06, 2021 by Administrator@rootContributor

Problem with aggregate initialization of std::string

Created by: mattiasm83

There seems to be a problem with aggregate initialization of std::string.

The variables b and c in the code below uses this:

std::string a = mqttConf[F("server")];
std::string b = {mqttConf[F("server")]};
std::string c{mqttConf[F("server")]};

Serial.println("----");
Serial.println(a.c_str());
Serial.println(b.c_str());
Serial.println(c.c_str());
Serial.println("----");

The output of the following code shows this:

----
192.168.1.1


----

Only the first initialization works.

If I use explicit casts to std::string on the aggregate intializations, like this:

std::string a = mqttConf[F("server")];
std::string b = {mqttConf[F("server")].as<std::string>()};
std::string c{mqttConf[F("server")].as<std::string>()};

then the output shows this (the expected output):

----
192.168.1.1
192.168.1.1
192.168.1.1
----

It this a known limitation, or is it a bug?

Assignee
Assign to
Time tracking