Skip to content

Enable compiler option "/Zc:__cplusplus" in Visual Studio backends with "/std:c++??" #15528

@boulette42

Description

@boulette42

When using Visual Studio as backend the macro __cplusplus is only set if the compiler option "/Zc:__cplusplus" is enabled.
If you use ninja as backend, the macro is set correctly.
You can reproduce it in this project:

meson.build

project(
  'c-version-test',
  ['cpp'],
  version: '1.0.0',
  default_options: [
    'buildtype=debugoptimized',
    'cpp_std=c++17'
  ]
)

executable(
  'c_version_test',
  sources: 'main.cpp',
  win_subsystem: 'console',
  install: true,
)

main.cpp

#include <iostream>

int main()
{
  if (__cplusplus >= 201703)
    std::cout << "std:c++17" << std::endl;
  else
    std::cout << "__cplusplus = " << __cplusplus << std::endl;
}

Running this after building with backend ninja you get

std:c++17

After building with backend vs2022 you get

__cplusplus = 199711

After setting

 'cpp_std=c++17'

in meson.build I would expect the first output whatever backend I use.

Windows 11 24H2, Visual Studio 2022, meson 1.10.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions