diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2021-10-17 09:22:29 -0400 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2021-10-17 09:23:43 -0400 |
commit | c8be7743acc7e8ea32ba9985c1d57c38f0eab010 (patch) | |
tree | 3251d94190dd99901be4bdd520bf7a4d5a2b7c93 | |
parent | 052b77e49f50e5796ee84a55c8a409b3ee41af22 (diff) | |
download | llvm-c8be7743acc7e8ea32ba9985c1d57c38f0eab010.tar.gz |
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.
-rw-r--r-- | clang/docs/ReleaseNotes.rst | 3 | ||||
-rw-r--r-- | clang/lib/Frontend/InitPreprocessor.cpp | 5 | ||||
-rw-r--r-- | clang/test/Preprocessor/c2x.c | 5 |
3 files changed, 12 insertions, 1 deletions
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 263eae83036d..27ff9ddc70a3 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 aa94b130cb12..a3e1ca5d5226 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 000000000000..96fc9273a286 --- /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__"); |