Skip to content

Commit b67d557

Browse files
committed
[C2y] Add -std=c2y and -std=gnu2y
This adds a language standard mode for the latest C standard. While WG14 is hoping for a three-year cycle, it is not clear that the next revision of C will be in 2026 and so a flag was not created for c26 specifically.
1 parent 6ad82fc commit b67d557

File tree

9 files changed

+47
-19
lines changed

9 files changed

+47
-19
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,12 @@ Resolutions to C++ Defect Reports
320320
C Language Changes
321321
------------------
322322

323+
C2y Feature Support
324+
^^^^^^^^^^^^^^^^^^^
325+
- Clang now enables C2y mode with ``-std=c2y``. This sets ``__STDC_VERSION__``
326+
to ``202400L`` so that it's greater than the value for C23. The value of this
327+
macro is subject to change in the future.
328+
323329
C23 Feature Support
324330
^^^^^^^^^^^^^^^^^^^
325331
- No longer diagnose use of binary literals as an extension in C23 mode. Fixes

clang/docs/UsersManual.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3458,9 +3458,9 @@ Differences between various standard modes
34583458

34593459
clang supports the -std option, which changes what language mode clang uses.
34603460
The supported modes for C are c89, gnu89, c94, c99, gnu99, c11, gnu11, c17,
3461-
gnu17, c23, gnu23, and various aliases for those modes. If no -std option is
3462-
specified, clang defaults to gnu17 mode. Many C99 and C11 features are
3463-
supported in earlier modes as a conforming extension, with a warning. Use
3461+
gnu17, c23, gnu23, c2y, gnu2y, and various aliases for those modes. If no -std
3462+
option is specified, clang defaults to gnu17 mode. Many C99 and C11 features
3463+
are supported in earlier modes as a conforming extension, with a warning. Use
34643464
``-pedantic-errors`` to request an error if a feature from a later standard
34653465
revision is used in an earlier mode.
34663466

@@ -3523,6 +3523,10 @@ Differences between ``*17`` and ``*23`` modes:
35233523
- ``[[]]`` attributes are supported by default in ``*23`` mode, and as an
35243524
extension in ``*17`` and earlier modes.
35253525

3526+
Differences between ``*23`` and ``*2y`` modes:
3527+
3528+
- ``__STDC_VERSION__`` is defined to ``202400L`` rather than ``202311L``.
3529+
35263530
GCC extensions not implemented yet
35273531
----------------------------------
35283532

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ LANGOPT(C99 , 1, 0, "C99")
8787
LANGOPT(C11 , 1, 0, "C11")
8888
LANGOPT(C17 , 1, 0, "C17")
8989
LANGOPT(C23 , 1, 0, "C23")
90+
LANGOPT(C2y , 1, 0, "C2y")
9091
LANGOPT(MSVCCompat , 1, 0, "Microsoft Visual C++ full compatibility mode")
9192
LANGOPT(Kernel , 1, 0, "Kernel mode")
9293
LANGOPT(MicrosoftExt , 1, 0, "Microsoft C++ extensions")

clang/include/clang/Basic/LangStandard.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,19 @@ enum LangFeatures {
5252
C11 = (1 << 2),
5353
C17 = (1 << 3),
5454
C23 = (1 << 4),
55-
CPlusPlus = (1 << 5),
56-
CPlusPlus11 = (1 << 6),
57-
CPlusPlus14 = (1 << 7),
58-
CPlusPlus17 = (1 << 8),
59-
CPlusPlus20 = (1 << 9),
60-
CPlusPlus23 = (1 << 10),
61-
CPlusPlus26 = (1 << 11),
62-
Digraphs = (1 << 12),
63-
GNUMode = (1 << 13),
64-
HexFloat = (1 << 14),
65-
OpenCL = (1 << 15),
66-
HLSL = (1 << 16)
55+
C2y = (1 << 5),
56+
CPlusPlus = (1 << 6),
57+
CPlusPlus11 = (1 << 7),
58+
CPlusPlus14 = (1 << 8),
59+
CPlusPlus17 = (1 << 9),
60+
CPlusPlus20 = (1 << 10),
61+
CPlusPlus23 = (1 << 11),
62+
CPlusPlus26 = (1 << 12),
63+
Digraphs = (1 << 13),
64+
GNUMode = (1 << 14),
65+
HexFloat = (1 << 15),
66+
OpenCL = (1 << 16),
67+
HLSL = (1 << 17)
6768
};
6869

6970
/// LangStandard - Information about the properties of a particular language
@@ -106,6 +107,9 @@ struct LangStandard {
106107
/// isC23 - Language is a superset of C23.
107108
bool isC23() const { return Flags & C23; }
108109

110+
/// isC2y - Language is a superset of C2y.
111+
bool isC2y() const { return Flags & C2y; }
112+
109113
/// isCPlusPlus - Language is a C++ variant.
110114
bool isCPlusPlus() const { return Flags & CPlusPlus; }
111115

clang/include/clang/Basic/LangStandards.def

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ LANGSTANDARD_ALIAS_DEPR(gnu23, "gnu2x")
9999
// FIXME: Add the alias for iso9899:202* once we know the year ISO publishes
100100
// the document (expected to be 2024).
101101

102+
// C2y modes
103+
LANGSTANDARD(c2y, "c2y",
104+
C, "Working Draft for ISO C2y",
105+
LineComment | C99 | C11 | C17 | C23 | C2y | Digraphs | HexFloat)
106+
LANGSTANDARD(gnu2y, "gnu2y",
107+
C, "Working Draft for ISO C2y with GNU extensions",
108+
LineComment | C99 | C11 | C17 | C23 | C2y | Digraphs | GNUMode | HexFloat)
109+
110+
102111
// C++ modes
103112
LANGSTANDARD(cxx98, "c++98",
104113
CXX, "ISO C++ 1998 with amendments",

clang/lib/Basic/LangOptions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ void LangOptions::setLangDefaults(LangOptions &Opts, Language Lang,
112112
Opts.C11 = Std.isC11();
113113
Opts.C17 = Std.isC17();
114114
Opts.C23 = Std.isC23();
115+
Opts.C2y = Std.isC2y();
115116
Opts.CPlusPlus = Std.isCPlusPlus();
116117
Opts.CPlusPlus11 = Std.isCPlusPlus11();
117118
Opts.CPlusPlus14 = Std.isCPlusPlus14();

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,9 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
448448
// value is, are implementation-defined.
449449
// (Removed in C++20.)
450450
if (!LangOpts.CPlusPlus) {
451-
if (LangOpts.C23)
451+
if (LangOpts.C2y)
452+
Builder.defineMacro("__STDC_VERSION__", "202400L");
453+
else if (LangOpts.C23)
452454
Builder.defineMacro("__STDC_VERSION__", "202311L");
453455
else if (LangOpts.C17)
454456
Builder.defineMacro("__STDC_VERSION__", "201710L");

clang/test/Driver/unknown-std.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
// CHECK-NEXT: note: use 'gnu17' or 'gnu18' for 'ISO C 2017 with GNU extensions' standard
1919
// CHECK-NEXT: note: use 'c23' for 'Working Draft for ISO C23' standard
2020
// CHECK-NEXT: note: use 'gnu23' for 'Working Draft for ISO C23 with GNU extensions' standard
21+
// CHECK-NEXT: note: use 'c2y' for 'Working Draft for ISO C2y' standard
22+
// CHECK-NEXT: note: use 'gnu2y' for 'Working Draft for ISO C2y with GNU extensions' standard
2123

2224
// Make sure that no other output is present.
2325
// CHECK-NOT: {{^.+$}}

clang/www/c_status.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ <h1>C Support in Clang</h1>
7171
</tr>
7272
<tr>
7373
<td><a href="#c2y">C2y</a></td>
74-
<td><tt>(Flag currently unavailable)</tt></td>
74+
<td><tt>-std=c2y</tt></td>
7575
<td class="partial" align="center">Partial</td>
7676
</tr>
7777
</table>
@@ -1229,8 +1229,7 @@ <h2 id="c2y">C2y implementation status</h2>
12291229

12301230
<p>Clang has support for some of the features of the C standard following C23, informally referred to as C2y.</p>
12311231

1232-
<p>Clang currently does not expose a language standard mode flag for C2y.
1233-
<!--You can use Clang in C2y mode with the <code>-std=c2y</code> option (available in Clang 19 and later).--></p>
1232+
<p>You can use Clang in C2y mode with the <code>-std=c2y</code> option (available in Clang 19 and later).</p>
12341233

12351234
<details open>
12361235
<summary>List of features and minimum Clang version with support</summary>

0 commit comments

Comments
 (0)