marzer / tomlplusplus

Header-only TOML config file parser and serializer for C++17.
https://marzer.github.io/tomlplusplus/
MIT License
1.53k stars 146 forks source link

Use of overloaded operator '=' is ambiguous (with operand types 'toml::table' and 'toml::parse_result') #170

Closed zzztttkkk closed 2 years ago

zzztttkkk commented 2 years ago

Environment

toml++ version and/or commit hash:
3.1.0 via vcpkg

Compiler:
vs 2022 17.3.2; clion

C++ standard mode:
20

Target arch:
x64

Describe the bug

It compiles and runs successfully, but the ide report a error. I do not why. This may be an ide problem, thanks.

Steps to reproduce (or a small repro code sample)

I also trying like this, but it can not be compiled.

auto result = toml::parse_file(fielpath);
if(result.failed()){
    ...
}
...

Additional information

screen_image

marzer commented 2 years ago

Ok, I'm confused. toml::parse_result is only a separate type when you're using exceptions, otherwise it's an alias for toml::table. If you're seeing it as a concrete type, then you have exceptions disabled, right? If you have them disabled, why are you doing try/catch in that screenshot? Something doesn't make sense here.

marzer commented 2 years ago

To be clear:

Using toml++ with Exceptions enabled:

toml::table tbl;
try
{
    tbl = toml::parse_file(some_path);
    // use your table
}
catch (const toml::parse_error& exc)
{
    // handle the error
}

Using toml++ with Exceptions disabled:

toml::parse_result result = toml::parse_file(some_path);
if (!result)
{
    // handle the error
}
else
{
    toml::table tbl = std::move(result);
    // use your table
}

Only one of these will compile, depending on your settings.

marzer commented 2 years ago

If you haven't disabled exceptions and are definitelly correct in using try/catch, then it's probably just your IDE being a bit confused. You can probably fix that by explicitly setting TOML_EXCEPTIONS to 1 somewhere before you include toml.h.

zzztttkkk commented 2 years ago

after #define TOML_EXCEPTIONS 1, It compiles and runs successfully, but the ide still report a error.

so it must be a ide bug, i can ignore it.

thanks.