[MSVC] Compile error in app\cxxopts.hpp with /std:c++20 or later
Hi, I work on MSVC compiler testing, and we regularly build popular open-source project, with development builds of MSVC in order to find and fix regressions before they ship and cause problems for you.
Note: You guys can go ahead to close this issue if HiGHS is not supporting c++20 or later.
Recently, when I was testing the compiler with Or_tools, which they are using HiGHS as one of their third-party libraries. I have discovered the following error:
C:\gitP\google\or-tools\build_amd64\_deps\highs-src\app\cxxopts.hpp(357,39):
error C2677: binary '+': no global operator found which takes type 'const std::string' (or there is no acceptable conversion)
[C:\gitP\google\or-tools\build_amd64\_deps\highs-build\app\highs-bin.vcxproj]
...
I believe this is because that string concatenation rules involving u8"..." (UTF-8 string literals) have changed in C++20 due to modifications in how UTF-8 string literals are handled. In C++20, u8"..." literals are now of type char8_t[] rather than const char[], which makes them incompatible with std::string out of the box.
// This won't compile in C++20 because of the type mismatch
std::string s = u8"Hello" + std::string(" World"); // Error
Steps to reproduce:
- Open x64 native tools command prompt for VS2022
- git clone https://github.com/google/or-tools.git
- cd google\or-tools
- set _CL_ = /std:c++latest
- mkdir build_amd64
- cd build_amd64
- cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_SYSTEM_VERSION=10.0.22621.0 -DBUILD_DEPS=ON .. 2>&1
- cmake --build . --config Release --target ALL_BUILD -v -- /maxcpucount 2>&1
build log: build.log
Thank you, we will look into resolving this! It is related to the command line options, which is an external code, may need an update and should not be necessary for or-tools anyway.
Hi @NEIL-smtg, thank you again for raising this, we have now updated the cxxopts which were causing trouble, and also moved them out of the library and into the runtime.
The changes are now merged in the development branch "latest" and will be included in our next release.
@galabovaa Great, thanks for the update hehe