Skip to content

Conversation

@frederick-vs-ja
Copy link
Contributor

Per P2493R0 and SD6, __cpp_constexpr of value 202002L indicates that P1330R0 "Changing the active member of a union inside constexpr" is implemented, which is true for Clang 9 and later.

Fixes #129730.

Per P2493R0 and SD6, `__cpp_constexpr` of value `202002L` indicates
that P1330R0 "Changing the active member of a union inside constexpr"
is implemented, which is true for Clang 9 and later.
@frederick-vs-ja frederick-vs-ja added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Mar 5, 2025
@frederick-vs-ja frederick-vs-ja requested a review from cor3ntin March 5, 2025 01:47
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Mar 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 5, 2025

@llvm/pr-subscribers-clang

Author: A. Jiang (frederick-vs-ja)

Changes

Per P2493R0 and SD6, __cpp_constexpr of value 202002L indicates that P1330R0 "Changing the active member of a union inside constexpr" is implemented, which is true for Clang 9 and later.

Fixes #129730.


Full diff: https://github.com/llvm/llvm-project/pull/129814.diff

3 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+3)
  • (modified) clang/lib/Frontend/InitPreprocessor.cpp (+1-1)
  • (modified) clang/test/Lexer/cxx-features.cpp (+1-1)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 37ea963bf337d..9b5bf115694f7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -96,6 +96,9 @@ Resolutions to C++ Defect Reports
 - Implemented `CWG2918 Consideration of constraints for address of overloaded `
   `function <https://cplusplus.github.io/CWG/issues/2918.html>`_
 
+- Bumped the ``__cpp_constexpr`` feature-test macro to ``202002L`` in C++20 mode as indicated in
+  `P2493R0 <https://wg21.link/P2493R0>`_.
+
 C Language Changes
 ------------------
 
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index e1dc728558def..1a816cb6269d4 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -664,7 +664,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
     Builder.defineMacro("__cpp_lambdas", "200907L");
     Builder.defineMacro("__cpp_constexpr", LangOpts.CPlusPlus26   ? "202406L"
                                            : LangOpts.CPlusPlus23 ? "202211L"
-                                           : LangOpts.CPlusPlus20 ? "201907L"
+                                           : LangOpts.CPlusPlus20 ? "202002L"
                                            : LangOpts.CPlusPlus17 ? "201603L"
                                            : LangOpts.CPlusPlus14 ? "201304L"
                                                                   : "200704");
diff --git a/clang/test/Lexer/cxx-features.cpp b/clang/test/Lexer/cxx-features.cpp
index ff9a1a1210c44..8c1867d5c7365 100644
--- a/clang/test/Lexer/cxx-features.cpp
+++ b/clang/test/Lexer/cxx-features.cpp
@@ -314,7 +314,7 @@
 #error "wrong value for __cpp_lambdas"
 #endif
 
-#if check(constexpr, 0, 200704, 201304, 201603, 201907, 202211, 202406L)
+#if check(constexpr, 0, 200704, 201304, 201603, 202002, 202211, 202406L)
 #error "wrong value for __cpp_constexpr"
 #endif
 

@frederick-vs-ja frederick-vs-ja merged commit d1bcac0 into llvm:main Mar 5, 2025
15 checks passed
@frederick-vs-ja frederick-vs-ja deleted the p1330r0-ftm branch March 5, 2025 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Value of __cpp_constexpr is incorrect for -std=c++20

3 participants