[clang] c8be774 - Bump the value of __STDC_VERSION__ in -std=c2x mode

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 17 06:23:52 PDT 2021


Author: Aaron Ballman
Date: 2021-10-17T09:23:43-04:00
New Revision: c8be7743acc7e8ea32ba9985c1d57c38f0eab010

URL: https://github.com/llvm/llvm-project/commit/c8be7743acc7e8ea32ba9985c1d57c38f0eab010
DIFF: https://github.com/llvm/llvm-project/commit/c8be7743acc7e8ea32ba9985c1d57c38f0eab010.diff

LOG: Bump the value of __STDC_VERSION__ in -std=c2x mode

Previously, we reported the same value as for C17, now we report 202000L, which
is the same value currently used by GCC.

Once C23 ships, this value will be bumped to the correct date.

Added: 
    clang/test/Preprocessor/c2x.c

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Frontend/InitPreprocessor.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 263eae83036df..27ff9ddc70a34 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -129,6 +129,9 @@ Windows Support
 C Language Changes in Clang
 ---------------------------
 
+- The value of ``__STDC_VERSION__`` has been bumped to ``202000L`` when passing
+  ``-std=c2x`` so that it can be distinguished from C17 mode. This value is
+  expected to change again when C23 is published.
 - Wide multi-characters literals such as ``L'ab'`` that would previously be interpreted as ``L'b'``
   are now ill-formed in all language modes. The motivation for this change is outlined in
   `P2362 <wg21.link/P2362>`_.

diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index aa94b130cb124..a3e1ca5d5226c 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -371,7 +371,10 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
   //      value is, are implementation-defined.
   // (Removed in C++20.)
   if (!LangOpts.CPlusPlus) {
-    if (LangOpts.C17)
+    // FIXME: Use correct value for C23.
+    if (LangOpts.C2x)
+      Builder.defineMacro("__STDC_VERSION__", "202000L");
+    else if (LangOpts.C17)
       Builder.defineMacro("__STDC_VERSION__", "201710L");
     else if (LangOpts.C11)
       Builder.defineMacro("__STDC_VERSION__", "201112L");

diff  --git a/clang/test/Preprocessor/c2x.c b/clang/test/Preprocessor/c2x.c
new file mode 100644
index 0000000000000..96fc9273a2868
--- /dev/null
+++ b/clang/test/Preprocessor/c2x.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c2x %s
+// expected-no-diagnostics
+
+// FIXME: Test the correct value once C23 ships.
+_Static_assert(__STDC_VERSION__ > 201710L, "Incorrect __STDC_VERSION__");


        


More information about the cfe-commits mailing list