From 0b97d585480e973d8b149618901f7a4ddfa1a906 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Sun, 8 Aug 2021 16:29:01 -0700 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 --- mesonbuild/compilers/cpp.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'mesonbuild/compilers') diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index 44155d1..057a39a 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -692,6 +692,17 @@ class VisualStudioCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixi del args[i] return args + def get_always_args(self) -> T.List[str]: + args = super().get_always_args() + + # update the __cplusplus #define to match the version given on the + # command line with /std:NNN, but only for versions above 15.7 (2017) + # https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-160 + if version_compare(self.version, '>= 15.7'): + args.append('/Zc:__cplusplus') + + return args + class ClangClCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixin, ClangClCompiler, CPPCompiler): def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, info: 'MachineInfo', target: str, -- cgit v1.1