From 04c728a126cc484cda21d21d672630d298cae9b8 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Wed, 27 Apr 2022 19:25:27 -0400 Subject: 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 Co-authored-by: Dylan Baker --- mesonbuild/compilers/cpp.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'mesonbuild/compilers/cpp.py') diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index fe09b6b60..4c24767ca 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' -- cgit v1.2.3