llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.71k stars 11.87k forks source link

Value of `_MSVC_LANG` should be larger than `202002L` in C++2b mode #50804

Closed f8e85f34-88d0-4ec5-bbf1-7aa1a2a92a2e closed 1 year ago

f8e85f34-88d0-4ec5-bbf1-7aa1a2a92a2e commented 3 years ago
Bugzilla Link 51462
Version trunk
OS Windows NT
CC @zygoloid

Extended Description

Currently _MSVC_LANG is defined as 201705L both in C++20 mode (/std:c++20 for clang-cl) and in C++2b mode (/std:c++latest for clang-cl). This prevents library code from discovering whether C++2b features are enabled.

The relevant code is in https://github.com/llvm/llvm-project/blob/1e11ccad837c2d0d848349e7bc8f5800e5d365fc/clang/lib/Basic/Targets/OSTargets.cpp#L183-L190 :

if (Opts.isCompatibleWithMSVC(LangOptions::MSVC2015)) {
  if (Opts.CPlusPlus20)
    Builder.defineMacro("_MSVC_LANG", "201705L");
  else if (Opts.CPlusPlus17)
    Builder.defineMacro("_MSVC_LANG", "201703L");
  else if (Opts.CPlusPlus14)
    Builder.defineMacro("_MSVC_LANG", "201402L");
}

For the reference, MSVC 2022 preview 3 (latest MSVC as of now) uses 202002L for C++20 and 202004L for C++2b.

CaseyCarter commented 2 years ago

Keeping _MSVC_LANG updated has been a chronic issue. Instead of trying to emulate MSVC's exact values, it may be easier and more effective to simply define _MSVC_LANG to be the same as __cplusplus. (Assuming, that is, that clang never chooses to emulate MSVC's behavior that __cplusplus is 199711L without /Zc:__cplusplus on the command line, which I would not recommend that you do.)

CaseyCarter commented 2 years ago

This issue seems to have been addressed by https://reviews.llvm.org/D114867 (defines _MSVC_LANG to 202002L in C++20 mode) and https://reviews.llvm.org/D114952 (defines _MSVC_LANG to 202004L in C++2b mode).

Is there any chance of getting these two patches ported to release/13.x for 13.0.1?

ilya-biryukov commented 1 year ago

Closing as this is fixed in head

llvmbot commented 1 year ago

@llvm/issue-subscribers-c-2b

llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-driver