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

ModelSkin.cpp, ambiguous operator compilation issue #4839

Closed
fluffyfreak opened this issue Mar 22, 2020 · 4 comments · Fixed by #4840
Closed

ModelSkin.cpp, ambiguous operator compilation issue #4839

fluffyfreak opened this issue Mar 22, 2020 · 4 comments · Fixed by #4840
Assignees

Comments

@fluffyfreak
Copy link
Contributor

fluffyfreak commented Mar 22, 2020

This is a compilation issue:
On Visual Studio, but also seen on other compilers apparently, the following error message occurs.

Error (active)	E0350	more than one operator "=" matches these operands:	scenegraph	D:\Code\PioneerGit\pioneer_fluffy\src\scenegraph\ModelSkin.cpp	114		            function "std::basic_string<_Elem, _Traits, _Alloc>::operator=(std::basic_string<_Elem, _Traits, _Alloc> &&_Right) [with _Elem=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]"
            function "std::basic_string<_Elem, _Traits, _Alloc>::operator=(std::initializer_list<_Elem> _Ilist) [with _Elem=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]"
            operand types are: std::string = nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t, uint64_t, double, std::allocator, nlohmann::adl_serializer>

@Web-eWorks as usual Visual Studio is being super helpful there with it's template expansion.
It says that it's an error, and has been there since 3a3a13e however the code still builds (obviously) and runs fine as far as I know.

@Gliese852
Copy link
Contributor

Here is the complete error log:

1>cl : command line warning D9035: option 'Gm' has been deprecated and will be removed in a future release
1>ModelSkin.cpp
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt_math_defines.h(22,1): warning C4005: 'M_PI': macro redefinition
1>D:\pioneer\build\pioneer-thirdparty\win32\include\SDL_stdinc.h(499): message : see previous definition of 'M_PI'
1>D:\pioneer\build\pioneer-ecraven-systemview-squashed\src\scenegraph\Serializer.h(48,1): warning C4267: 'argument': conversion from 'size_t' to 'const T', possible loss of data
1>        with
1>        [
1>            T=Uint32
1>        ]
1>D:\pioneer\build\pioneer-ecraven-systemview-squashed\src\scenegraph\Serializer.h(59,1): warning C4267: 'initializing': conversion from 'size_t' to 'Uint32', possible loss of data
1>D:\pioneer\build\pioneer-ecraven-systemview-squashed\src\scenegraph\Serializer.h(83,1): warning C4267: 'argument': conversion from 'size_t' to 'Uint32', possible loss of data
1>D:\pioneer\build\pioneer-ecraven-systemview-squashed\src\scenegraph\ModelSkin.cpp(114,37): error C2593: 'operator =' is ambiguous
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\xstring(2591,19): message : could be 'std::basic_string<char,std::char_traits<char>,std::allocator<char>> &std::basic_string<char,std::char_traits<char>,std::allocator<char>>::operator =(std::initializer_list<_Elem>)'
1>        with
1>        [
1>            _Elem=char
1>        ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\xstring(2492,19): message : or       'std::basic_string<char,std::char_traits<char>,std::allocator<char>> &std::basic_string<char,std::char_traits<char>,std::allocator<char>>::operator =(std::basic_string<char,std::char_traits<char>,std::allocator<char>> &&) noexcept'
1>D:\pioneer\build\pioneer-ecraven-systemview-squashed\src\scenegraph\ModelSkin.cpp(114,37): message : while trying to match the argument list '(std::string, nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>)'
1>D:\pioneer\build\pioneer-ecraven-systemview-squashed\src\scenegraph\ModelSkin.cpp(117,35): error C2593: 'operator =' is ambiguous
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\xstring(2591,19): message : could be 'std::basic_string<char,std::char_traits<char>,std::allocator<char>> &std::basic_string<char,std::char_traits<char>,std::allocator<char>>::operator =(std::initializer_list<_Elem>)'
1>        with
1>        [
1>            _Elem=char
1>        ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\xstring(2492,19): message : or       'std::basic_string<char,std::char_traits<char>,std::allocator<char>> &std::basic_string<char,std::char_traits<char>,std::allocator<char>>::operator =(std::basic_string<char,std::char_traits<char>,std::allocator<char>> &&) noexcept'
1>D:\pioneer\build\pioneer-ecraven-systemview-squashed\src\scenegraph\ModelSkin.cpp(117,35): message : while trying to match the argument list '(std::string, nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>)'
1>Done building project "newmodel.vcxproj" -- FAILED.
2>------ Build started: Project: pioneer, Configuration: Release x64 ------
2>cl : command line warning D9025: overriding '/sdl-' with '/GS-'
2>cl : command line warning D9025: overriding '/sdl-' with '/GS-'
2>cl : command line warning D9025: overriding '/sdl-' with '/GS-'
2>Body.cpp
2>Frame.cpp
2>cl : command line warning D9025: overriding '/sdl-' with '/GS-'
2>Ship.cpp
2>D:\pioneer\build\pioneer-ecraven-systemview-squashed\src\Frame.cpp(31,28): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
2>D:\pioneer\build\pioneer-ecraven-systemview-squashed\src\Frame.cpp(36,49): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
2>D:\pioneer\build\pioneer-ecraven-systemview-squashed\src\Frame.cpp(61,28): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
2>D:\pioneer\build\pioneer-ecraven-systemview-squashed\src\Frame.cpp(170,30): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
2>D:\pioneer\build\pioneer-ecraven-systemview-squashed\src\Frame.cpp(195,33): error C2593: 'operator =' is ambiguous
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\xstring(2591,19): message : could be 'std::basic_string<char,std::char_traits<char>,std::allocator<char>> &std::basic_string<char,std::char_traits<char>,std::allocator<char>>::operator =(std::initializer_list<_Elem>)'
2>        with
2>        [
2>            _Elem=char
2>        ] (compiling source file ..\..\src\Frame.cpp)
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\xstring(2492,19): message : or       'std::basic_string<char,std::char_traits<char>,std::allocator<char>> &std::basic_string<char,std::char_traits<char>,std::allocator<char>>::operator =(std::basic_string<char,std::char_traits<char>,std::allocator<char>> &&) noexcept' (compiling source file ..\..\src\Frame.cpp)
2>D:\pioneer\build\pioneer-ecraven-systemview-squashed\src\Frame.cpp(195,33): message : while trying to match the argument list '(std::string, const nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>)'
2>D:\pioneer\build\pioneer-ecraven-systemview-squashed\src\Frame.cpp(261,30): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
2>D:\pioneer\build\pioneer-ecraven-systemview-squashed\src\Body.cpp(47,29): error C2593: 'operator =' is ambiguous
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\xstring(2591,19): message : could be 'std::basic_string<char,std::char_traits<char>,std::allocator<char>> &std::basic_string<char,std::char_traits<char>,std::allocator<char>>::operator =(std::initializer_list<_Elem>)'
2>        with
2>        [
2>            _Elem=char
2>        ] (compiling source file ..\..\src\Body.cpp)
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\xstring(2492,19): message : or       'std::basic_string<char,std::char_traits<char>,std::allocator<char>> &std::basic_string<char,std::char_traits<char>,std::allocator<char>>::operator =(std::basic_string<char,std::char_traits<char>,std::allocator<char>> &&) noexcept(<expr>)' (compiling source file ..\..\src\Body.cpp)
2>D:\pioneer\build\pioneer-ecraven-systemview-squashed\src\Body.cpp(47,29): message : while trying to match the argument list '(std::string, nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>)'
2>D:\pioneer\build\pioneer-ecraven-systemview-squashed\src\Ship.cpp(191,31): error C2593: 'operator =' is ambiguous
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\xstring(2591,19): message : could be 'std::basic_string<char,std::char_traits<char>,std::allocator<char>> &std::basic_string<char,std::char_traits<char>,std::allocator<char>>::operator =(std::initializer_list<_Elem>)'
2>        with
2>        [
2>            _Elem=char
2>        ] (compiling source file ..\..\src\Ship.cpp)
2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\xstring(2492,19): message : or       'std::basic_string<char,std::char_traits<char>,std::allocator<char>> &std::basic_string<char,std::char_traits<char>,std::allocator<char>>::operator =(std::basic_string<char,std::char_traits<char>,std::allocator<char>> &&) noexcept' (compiling source file ..\..\src\Ship.cpp)
2>D:\pioneer\build\pioneer-ecraven-systemview-squashed\src\Ship.cpp(191,31): message : while trying to match the argument list '(std::string, nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>)'
2>Done building project "pioneer.vcxproj" -- FAILED.
========== Build: 0 succeeded, 2 failed, 13 up-to-date, 0 skipped ==========

The compiler swears at:

m_label = bodyObj["label"];

f->m_label = frameObj["label"];

m_decals[i] = arrayElem["decal"];

m_label = modelSkinObj["label"];

m_shipName = shipObj["name"];

I would like to clarify that I personally do not have such a problem.
(gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0)

@Web-eWorks
Copy link
Member

Hmm... looks like VS is complaining that a Json value can be converted to either a std::string or a std::initializer_list and both match operator=() implementations... for some reason. I don't know why this is such a major malfunction for VS, but I'm pretty sure it's due to the way MSVC handles implicit type conversion (really, what I mean is how badly MSVC handles implicit type conversion).

I haven't noticed any breaking issues with the MSVC compilation on appveyor, but you can simply convert each of those call sites to e.g. f->m_label = frameObj["label"].get<std::string>() with no issues AFAIK.

@Web-eWorks
Copy link
Member

Web-eWorks commented Mar 23, 2020

Given the discussion here (have I linked this before? It seems familiar...), my best guess is that there's a std::string constructor in newer versions of MSVC that is throwing those errors. In general, looks like we can simply call .get<T>() and be done.

Overall, it looks like we should be using .get<T>() on everything, or at least some kind of wizardry to avoid operator= nonsense, but that can be left for another day.

@fluffyfreak
Copy link
Contributor Author

on it

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

Successfully merging a pull request may close this issue.

3 participants