[clang] [Clang] Bump `__cpp_constexpr` to `202002L` in C++20 mode (PR #129814)

A. Jiang via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 4 17:48:00 PST 2025


https://github.com/frederick-vs-ja created https://github.com/llvm/llvm-project/pull/129814

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.

>From 002490cf1979bbbecef3bc0958ef413f5b85f849 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Wed, 5 Mar 2025 09:41:33 +0800
Subject: [PATCH] [Clang] Bump `__cpp_constexpr` to `202002L` in C++20 mode

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.
---
 clang/docs/ReleaseNotes.rst             | 3 +++
 clang/lib/Frontend/InitPreprocessor.cpp | 2 +-
 clang/test/Lexer/cxx-features.cpp       | 2 +-
 3 files changed, 5 insertions(+), 2 deletions(-)

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
 



More information about the cfe-commits mailing list