JoeyDeVries / LearnOpenGL

Code repository of all OpenGL chapters from the book and its accompanying website https://learnopengl.com
https://learnopengl.com
Other
11.06k stars 2.8k forks source link

[MSVC][std:c++latest] error C2668: 'lerp': ambiguous call to overloaded function #330

Open QuellaZhang opened 2 years ago

QuellaZhang commented 2 years ago

Hi All,

The MSVC team recently added LearnOpenGL as part of RWC testing. And we found some errors when building LearnOpenGL with '/std:c++latest'. Could you please help look at this issue? Thanks in advance. Looks like "lerp" needs to be renamed. See https://en.cppreference.com/w/cpp/numeric/lerp.

Build steps:

  1. Open VS2019 x64 native tools
  2. git clone https://github.com/JoeyDeVries/LearnOpenGL.git F:\gitP\JoeyDeVries\LearnOpenGL
  3. set CL=/std:c++latest
  4. mkdir F:\gitP\JoeyDeVries\LearnOpenGL\build_amd64
  5. cd F:\gitP\JoeyDeVries\LearnOpenGL\build_amd64
  6. cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_SYSTEM_VERSION=10.0.18362.0 -DCMAKE_BUILD_TYPE=Release ..
  7. msbuild /m /p:Platform=x64 /p:Configuration=Release LearnOpenGL.sln /t:Rebuild /p:BuildInParallel=true

Error info: F:\gitP\JoeyDeVries\LearnOpenGL\src\5.advanced_lighting\9.ssao\ssao.cpp(179): error C2668: 'lerp': ambiguous call to overloaded function F:\gitP\JoeyDeVries\LearnOpenGL\src\5.advanced_lighting\9.ssao\ssao.cpp(38): note: could be 'float lerp(float,float,float)' C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\cmath(1314): note: or 'float std::lerp(const float,const float,const float) noexcept' F:\gitP\JoeyDeVries\LearnOpenGL\src\5.advanced_lighting\9.ssao\ssao.cpp(179): note: while trying to match the argument list '(float, float, float)'

JoeyDeVries commented 2 years ago

Hey, thank you for the report! I'm a bit confused, is it that the latest version of C++ has a globally defined lerp function without the need for any namespace specifier (like std::)? I simply use a custom lerp function defined high up in the file and since I have no default namespace specifier (e.g. using namespace std;) I don't see how this would conflict.

Only if latest C++ version has a globally included lerp call without namespace specifiers which would seem like a really risky move on the C++ comittee. I can easily fix it on my end, but this could be a bigger flag?

QuellaZhang commented 2 years ago

@JoeyDeVries, I simply looked into the issue, lerpfunction was defined in stdnamespace in MSVC. image

And I found some other headers include using namespace std;. If you add /showIncludes option when compiling F:\gitP\JoeyDeVries\LearnOpenGL\src\5.advanced_lighting\9.ssao\ssao.cpp, you will get all header files and find that it includes mesh.h, it will also include using namespace std;.

image

header_files.txt

JoeyDeVries commented 2 years ago

@QuellaZhang oh of course! Didn't consider the header includes for a bit. I should get rid of the using namespace std parts, but would require a lot of testing to see if everything still works. I've renamed the lerp call for now to get rid of the ambiguity. Thanks for looking into it!