Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brace constructing a toml::value inserts a new array element in GCC 10.2.1 #165

Open
andrewkcorcoran opened this issue Jun 23, 2021 · 2 comments

Comments

@andrewkcorcoran
Copy link

toml11v3.7.0

The toml2 variable in the below example is copy constructed incorrectly and has an empty array inserted on GCC but is correctly constructed on clang. The error looks to be to do with the toml::value std::intializer_list constructor std::enable_if being too broad (toml/value.hpp:840).

  #include <iostream>
  #include <sstream>

  #include "toml.hpp"

  int main()
  {
      auto stream = std::istringstream{"a = 1"};
      auto toml1 = toml::parse(stream);
      auto toml2 = toml::value{toml1};
      auto toml3 = toml::value(toml1);
      std::cout << toml1 << toml2 << toml3;
      return EXIT_SUCCESS;
  }
$ g++ --version
g++ (GCC) 10.2.1 20200804 (Red Hat 10.2.1-2)
./mva_gcc
a = 1
[[]]
a = 1
a = 1

$ clang++ --version
clang version 10.0.1 (Red Hat 10.0.1-4.el7)
./mva_clang
a = 1
a = 1
a = 1
MartinHelmut added a commit to krieselreihe/litr that referenced this issue Mar 31, 2022
This is currently a workaround to mitigate an issue in Toml11: ToruNiina/toml11#165
MartinHelmut added a commit to krieselreihe/litr that referenced this issue Mar 31, 2022
This is currently a workaround to mitigate an issue in Toml11: ToruNiina/toml11#165
MartinHelmut added a commit to krieselreihe/litr that referenced this issue Mar 31, 2022
This is currently a workaround to mitigate an issue in Toml11: ToruNiina/toml11#165
@jackwil1
Copy link

I am also having this issue

@vadz
Copy link

vadz commented May 21, 2024

This is really not a nice problem to run into when initializing a class member with the result of parse(), e.g.

struct config_file {
  explicit config_file(const char* filename) : root_{toml::parse(filename)} {}

  const toml::value root_;
};

results in root_ being an array, completely unexpectedly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants