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

Update compiler workarounds for MSVC 2022 #124

Closed
NancyLi1013 opened this issue Oct 11, 2021 · 7 comments
Closed

Update compiler workarounds for MSVC 2022 #124

NancyLi1013 opened this issue Oct 11, 2021 · 7 comments

Comments

@NancyLi1013
Copy link

Hi @mosra,

I'm a member of Microsoft vcpkg team. In our latest internal test, corrade installation failed with following error:

FAILED: src/Corrade/Utility/CMakeFiles/CorradeUtilityObjects.dir/TweakableParser.cpp.obj 
"E:\Visual Studio\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe"   /TP -DCORRADE_IS_DEBUG_BUILD -DCorradeUtilityObjects_EXPORTS -DNOMINMAX -DUNICODE -DWIN32_LEAN_AND_MEAN -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -IC:\vcpkg_1011\vcpkg\buildtrees\corrade\src\v2020.06-2e11614b58\src -IC:\vcpkg_1011\vcpkg\buildtrees\corrade\x64-windows-dbg\src /nologo /DWIN32 /D_WINDOWS  /utf-8 /GR /EHsc /MP  /D_DEBUG /MDd /Z7 /Ob0 /Od /RTC1  /W4 /wd4251 /wd4244 /wd4267 /wd4351 /wd4373 /wd4510 /wd4610 /wd4512 /wd4661 /wd4702 /wd4706 /wd4800 /wd4910 /showIncludes /Fosrc\Corrade\Utility\CMakeFiles\CorradeUtilityObjects.dir\TweakableParser.cpp.obj /Fdsrc\Corrade\Utility\CMakeFiles\CorradeUtilityObjects.dir\ /FS -c C:\vcpkg_1011\vcpkg\buildtrees\corrade\src\v2020.06-2e11614b58\src\Corrade\Utility\TweakableParser.cpp
C:\vcpkg_1011\vcpkg\buildtrees\corrade\src\v2020.06-2e11614b58\src\Corrade\Utility\TweakableParser.cpp(40): error C2666: '+': 2 overloads have similar conversions
C:\vcpkg_1011\vcpkg\buildtrees\corrade\src\v2020.06-2e11614b58\src\Corrade\Utility\TweakableParser.cpp(40): note: could be 'built-in C++ operator+(bool, int)'
C:\vcpkg_1011\vcpkg\buildtrees\corrade\src\v2020.06-2e11614b58\src\Corrade\Utility\TweakableParser.cpp(40): note: or       'built-in C++ operator+(const T, __int64)'
        with
        [
            T=const char
        ]
C:\vcpkg_1011\vcpkg\buildtrees\corrade\src\v2020.06-2e11614b58\src\Corrade\Utility\TweakableParser.cpp(40): note: while trying to match the argument list '(Corrade::Containers::ArrayView<const char>, int)'
C:\vcpkg_1011\vcpkg\buildtrees\corrade\src\v2020.06-2e11614b58\src\Corrade\Utility\TweakableParser.cpp(40): error C2440: 'return': cannot convert from 'initializer list' to 'std::pair<const char *,int>'
C:\vcpkg_1011\vcpkg\buildtrees\corrade\src\v2020.06-2e11614b58\src\Corrade\Utility\TweakableParser.cpp(40): note: No constructor could take the source type, or constructor overload resolution was ambiguous
C:\vcpkg_1011\vcpkg\buildtrees\corrade\src\v2020.06-2e11614b58\src\Corrade\Utility\TweakableParser.cpp(42): error C2666: '+': 2 overloads have similar conversions
C:\vcpkg_1011\vcpkg\buildtrees\corrade\src\v2020.06-2e11614b58\src\Corrade\Utility\TweakableParser.cpp(42): note: could be 'built-in C++ operator+(bool, int)'
C:\vcpkg_1011\vcpkg\buildtrees\corrade\src\v2020.06-2e11614b58\src\Corrade\Utility\TweakableParser.cpp(42): note: or       'built-in C++ operator+(const T, __int64)'
        with
        [
            T=const char
        ]

After investigation, we found that it was caused by the value of CMAKE_CXX_COMPILER_VERSION. It has become 19.31.30710.95 in interval version of Visual Studio, which is out of range 19.30 in Visual Studio 2019.

Seems corrade needs to support Visual Studio 2022. Could you please help look into and confirm this issue?

Thanks in advance.

@mosra mosra added this to the 2020.0b milestone Oct 11, 2021
@mosra
Copy link
Owner

mosra commented Oct 11, 2021

Hi,

I got a similar report about a month ago from @Auburn who was trying out the 2022 Preview, but didn't have a chance to make a fix yet -- waiting on AppVeyor CI to make 2022 Preview available (appveyor/ci#3712). Sorry about that. In the meantime, passing -DMSVC2019_COMPATIBILITY=ON to CMake should make it compile I think.

A bit of background, I have a set of VS-specific workarounds, but those are conservatively enabled only for versions that I know about, in an anticipation that they'll get obsoleted with newer versions (most of them did so far, allowing me to gradually clean them up, which is great). For this particular error however, I suppose the behavior differs with the /permissive- flag being set or not, right?

@NancyLi1013
Copy link
Author

Thanks for your instant reply @mosra.

I have tried to build corrade with the flag /permissive-, the errors disappear. So you're right.

@mosra
Copy link
Owner

mosra commented Oct 11, 2021

Ah, great. Do you know if there's a way to detect from the preprocessor if the /permissive- flag is set? So I could enable the corresponding workaround only for builds without the flag, or until this flag becomes a default, instead of always.

I was looking for a way to do that a few times already, but couldn't find any macro describing the level of enabled standard conformance.

Thank you!

@NancyLi1013
Copy link
Author

Do you know if there's a way to detect from the preprocessor if the /permissive- flag is set?

Sorry, I don't know how to detect it. But we could add /std:c++latest to enable this option.
The /permissive- option is implicitly set by the /std:c++latest option starting in Visual Studio 2019 version 16.8, and in version 16.11 by the /std:c++20 option.
https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=msvc-160#remarks

@mosra
Copy link
Owner

mosra commented Oct 11, 2021

Thanks for the information, good to know that the /std: flags enable it implicltly. Unfortunately for me these have other implications so I'd like to stay at the C++11/14 mode for now.

I had a look at the code in question and got changed in current master, so the PR you just opened is probably the best way to fix that right now :) Once I'll get to creating a new tagged release (mosra/magnum#453), I'll make sure it works properly with VS 2022.

@mosra mosra changed the title corrade build failed in an internal version of Visual Studio Update compiler workarounds for MSVC 2022 Oct 11, 2021
@Auburn
Copy link

Auburn commented Dec 8, 2021

To bump this, looks like AppVeyor CI has added VS 2022 support now

Setting MSVC2019_COMPATIBILITY does still fix the compile issues in the release version of VS2022

@mosra
Copy link
Owner

mosra commented Feb 8, 2022

As of 00cfbbb there's a new CORRADE_MSVC_COMPATIBILITY option which supersedes CORRADE_MSVC2019_COMPATIBILITY (removed in 316205e), and is enabled by default on MSVC 2019+. This option now covers everything that's fixed by /permissive- -- if you set this compiler flag for all files, you can disable CORRADE_MSVC_COMPATIBILITY and live workaround-free on MSVC 2019 and newer. For 2017 and older there's still the CORRADE_MSVC{2017,2015}_COMPATIBILITY and /permissive- makes it do weird things, so please don't try setting the flag there.

Commits a72eea8, 2fa0ba1, mosra/magnum@acc17f0, mosra/magnum@4d574b0, mosra/magnum@efcdfc1 and mosra/magnum-plugins@18a1d60 make Corrade, Magnum and Magnum Plugins work with both MSVC 2019 and 2022, both with and without the /permissive- flag. The CI now also tests for /permissive- builds on 2019 and 2022, to catch issues happening only with this flag enabled. Other repositories don't have any known workarounds for MSVC 2019 so I expect them to work with 2022 without issues, CI builds for these will be added over the next days/weeks.

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

No branches or pull requests

3 participants