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

Unexpected result with std::string_view on different platform #182

Closed
J-Roux opened this issue Dec 16, 2021 · 4 comments
Closed

Unexpected result with std::string_view on different platform #182

J-Roux opened this issue Dec 16, 2021 · 4 comments

Comments

@J-Roux
Copy link

J-Roux commented Dec 16, 2021

TEST(toml, bug)
{
  toml::value table{};
  std::string_view data = "hello";
  table["data"] = data;
  std::cout << table << std::endl;
}

On Linux gcc 11.2

1: [ RUN      ] toml.bug
1: data = "hello"
1: 
1: [       OK ] toml.bug (0 ms)

On Windows MSVC 19.29.30136.0
I expected same result and same type(string) like on Linux, but got char array.

[ RUN      ] toml.bug
data = [
104,
101,
108,
108,
111,
]

[       OK ] toml.bug (0 ms)
@ToruNiina
Copy link
Owner

That is wired because we always test that feature and it passes on CI with various versions of MSVC.

Although I'm not 100% sure because I don't know your configuration, I think the reason why you got a weird result is that you don't set /Zc:__cplusplus in your MSVC configuration. It defines a macro __cplusplus correctly that is used to detect the version and used when checking if the environment has <string_view>. The macro is guaranteed to be defined by the C++ spec, but MSVC does not define it correctly unless you pass the flag, maybe because of a historical reason or for the sake of backward compatibility or something like that.

FYI: https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-170

@basiliscos
Copy link

Can some macros be defined, to force the behavior of inclusion of std::string_view ? It is quite unhandy to carry /Zc:__cplusplus for all dependent projects of header-only library?

@ToruNiina
Copy link
Owner

I added a workaround for MSVC's standard incompliant behavior, so now it works without /Zc:__cplusplus. I think this would help in most cases.

You can also use TOML11_ENFORCE_CXX11, 14, 17, 20 to use the feature of the specified standard regardless of what the compiler says.

@basiliscos
Copy link

Perfect, thank you. When to expect the release of new version of toml11?

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