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

Compilation error using C++ 20 and VS 16.11.1 (C++ 17 works) #2070

Closed
CyberDani opened this issue Aug 25, 2021 · 5 comments
Closed

Compilation error using C++ 20 and VS 16.11.1 (C++ 17 works) #2070

CyberDani opened this issue Aug 25, 2021 · 5 comments

Comments

@CyberDani
Copy link

I am using the following environment:
Visual Studio 2019 - 16.11.1 (latest release at the time of writing)
MSVC 19.29.30133.0 (used by cmake and VS)
ISO C++20 Standard (/std:c++20)
spdlog commit 5df9b11, v 1.9.2, branch v1.x (latest at the time of writing)
Platform toolset: Visual Studio 2019 (v142)

I have a C++ project where I have the spdlog dependencies included and only by having the following line in my code:

#include "spdlog/spdlog.h"

.. the compiler gives the following errors:

C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\winbase.h(9531,5): warning C5105: macro expansion producing 'defined' has undefined behavior
2>E:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xhash(114,53): error C2064: term does not evaluate to a function taking 1 arguments
2>E:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xhash(138): message : see reference to variable template 'const bool _Nothrow_hash<std::hash<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > >' being compiled
2>E:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xhash(138): message : while compiling class template member function 'size_t std::_Uhash_compare<_Kty,_Hasher,_Keyeq>::operator ()<std::string>(const _Keyty &) noexcept(<expr>) const'
2>        with
2>        [
2>            _Kty=std::string,
2>            _Hasher=std::hash<std::string>,
2>            _Keyeq=std::equal_to<std::string>,
2>            _Keyty=std::string
2>        ]
2>E:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xhash(1083): message : see reference to variable template 'const bool _Nothrow_hash<std::_Umap_traits<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::shared_ptr<spdlog::logger>,std::_Uhash_compare<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::hash<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::equal_to<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >,std::allocator<std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,std::shared_ptr<spdlog::logger> > >,0>,std::basic_string<char,std::char_traits<char>,std::allocator<char> > >' being compiled
2>E:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xhash(113,44): error C2056: illegal expression
2>Done building project "GameServerConsole.vcxproj" -- FAILED.

Notes:

  • If a change the C++ version to 17, the project compiles (however the project i am working on uses C++ 20 features, so changing the C++ version is not a workaround for me)
  • This issue appeared 3 months ago (5/24/2021 was the last date when it worked) after I installed a new version of Visual Studio 2019 (before it worked fine with the incomplete C++ 20 draft - I have waited with opening this issue because I hoped it will be fixed either by a new commit or a newer VS release)
  • Building the spdlog lib files with C++ 20 does not solve the issue
  • Defining SPDLOG_HEADER_ONLY does not solve the issue (same error)
  • Defining SPDLOG_FMT_EXTERNAL seems to create even more errors (I have set up fmt 1.7.3 particularly for this test)

Since it works with C++17 and it already worked with later VS releases I think that it is not a dependency problem or a misconfiguration somewhere. If you think it is, please give me suggestions. Having this issue fixed would be very helpful. 🙏

@tt4g
Copy link
Contributor

tt4g commented Aug 25, 2021

It's a Windows SDK (10.0.19041.0) bug: https://developercommunity2.visualstudio.com/t/std:c17-generates-warning-compiling-Win/1249671?preview=true

Update Windows SDK (10.0.20348.0).

@CyberDani
Copy link
Author

Thank you for the quick answer!

I have updated the Windows SDK as you suggested and also rebuilt the library files with the new SDK. My VS project now uses the new SDK version. Indeed the first warning related to Windows SDK disappeared, but the issue is still valid:

1>E:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xhash(114,53): error C2064: term does not evaluate to a function taking 1 arguments
1>E:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xhash(138): message : see reference to variable template 'const bool _Nothrow_hash<std::hash<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > >' being compiled
1>E:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xhash(138): message : while compiling class template member function 'size_t std::_Uhash_compare<_Kty,_Hasher,_Keyeq>::operator ()<std::string>(const _Keyty &) noexcept(<expr>) const'
1>        with
1>        [
1>            _Kty=std::string,
1>            _Hasher=std::hash<std::string>,
1>            _Keyeq=std::equal_to<std::string>,
1>            _Keyty=std::string
1>        ]
1>E:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xhash(1083): message : see reference to variable template 'const bool _Nothrow_hash<std::_Umap_traits<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::shared_ptr<spdlog::logger>,std::_Uhash_compare<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::hash<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::equal_to<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >,std::allocator<std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,std::shared_ptr<spdlog::logger> > >,0>,std::basic_string<char,std::char_traits<char>,std::allocator<char> > >' being compiled
1>E:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xhash(113,44): error C2056: illegal expression
1>Done building project "GameServerConsole.vcxproj" -- FAILED.

@tt4g
Copy link
Contributor

tt4g commented Aug 25, 2021

Template specialization of std::hash used by std::unordered_map<std::string, std::shared_ptr<spdlog::logger> in file E:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xhash seems to have failed.

However, std::hash<std::string> and std::hash<std::shared_ptr<T>> are defined in the C++11 standard.

I think you should open an MSVC issue.

@CyberDani
Copy link
Author

Sorry for the late answer. As you suggested I have created an MSVC issue, it can be accessed at the following link: Template specialization fails using C++20 (spdlog lib fails)

Will come back to inform you if the case makes progreess.

@CyberDani
Copy link
Author

CyberDani commented Sep 2, 2021

We have a workaround / solution for this issue.

Removing the "/translateinclude" (documentation) option from the MSVC compiler solves the compilation issue now.

This is a MSVC issue which is being investigated now. For further information and improvements please follow the MSVC case linked in my previous comment as new helpful feedbacks might still come from Microsoft.

Thank you for taking a look and giving suggestions! 😄

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

No branches or pull requests

3 participants