diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2022-04-27 19:25:27 -0400 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2022-05-08 14:40:54 -0400 |
commit | 04c728a126cc484cda21d21d672630d298cae9b8 (patch) | |
tree | a94355772115790675f67e79932f3d3dc2157d5c /mesonbuild/compilers | |
parent | 3ae36dee42e0152ed24a385fdd6035a391f5322f (diff) | |
download | meson-04c728a126cc484cda21d21d672630d298cae9b8.zip meson-04c728a126cc484cda21d21d672630d298cae9b8.tar.gz meson-04c728a126cc484cda21d21d672630d298cae9b8.tar.bz2 |
compilers/c++: Add MSVC option to make the __cplusplus define accurate
Otherwise it always returns the value for c++98, starting with MSVC 2017
15.7 or later. Earlier versions are not affected by this mis-feature.
See: https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-160
This was originally applied as 0b97d585480e973d8b149618901f7a4ddfa1a906
but later reverted because it made the CI red. Try it again, now.
Original-patch-by: Dylan Baker <dylan@pnwbakers.com>
Co-authored-by: Dylan Baker <dylan@pnwbakers.com>
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r-- | mesonbuild/compilers/cpp.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index fe09b6b..4c24767 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -734,6 +734,16 @@ class VisualStudioCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixi del args[i] return args + def get_always_args(self) -> T.List[str]: + args = super().get_always_args() + + # By default, MSVC has a broken __cplusplus define that pretends to be c++98: + # https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-160 + # Pass the flag to enable a truthful define, if possible. + if version_compare(self.version, '>= 15.7') and '/Zc:__cplusplus' not in args: + return args + ['/Zc:__cplusplus'] + return args + class ClangClCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixin, ClangClCompiler, CPPCompiler): id = 'clang-cl' |