[clang] b763d6a - Add C++26 compile flags.
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Mon May 15 08:56:31 PDT 2023
Author: Erich Keane
Date: 2023-05-15T08:56:16-07:00
New Revision: b763d6a4ed4650c74c6846d743156468563b0e31
URL: https://github.com/llvm/llvm-project/commit/b763d6a4ed4650c74c6846d743156468563b0e31
DIFF: https://github.com/llvm/llvm-project/commit/b763d6a4ed4650c74c6846d743156468563b0e31.diff
LOG: Add C++26 compile flags.
Now that we've updated to C++23, we need to add C++26/C++2c command line
flags, as discussed in
https://discourse.llvm.org/t/rfc-lets-just-call-it-c-26-and-forget-about-the-c-2c-business-at-least-internally/70383
Differential Revision: https://reviews.llvm.org/D150450
Added:
Modified:
clang/docs/CommandGuide/clang.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Basic/LangStandard.h
clang/include/clang/Basic/LangStandards.def
clang/lib/Basic/LangOptions.cpp
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/Driver/cl-options.c
clang/test/Driver/unknown-std.cpp
clang/test/Preprocessor/init.c
clang/www/OpenProjects.html
clang/www/cxx_status.html
Removed:
################################################################################
diff --git a/clang/docs/CommandGuide/clang.rst b/clang/docs/CommandGuide/clang.rst
index 6c59ffd2ab120..faaf9c8d97ef3 100644
--- a/clang/docs/CommandGuide/clang.rst
+++ b/clang/docs/CommandGuide/clang.rst
@@ -201,6 +201,14 @@ Language Selection and Mode Options
ISO C++ 2023 with amendments and GNU extensions
+ | ``c++2c``
+
+ Working draft for C++2c
+
+ | ``gnu++2c``
+
+ Working draft for C++2c with GNU extensions
+
The default C++ language standard is ``gnu++17``.
Supported values for the OpenCL language are:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7e8dca8b31871..9601849bd67d3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -109,6 +109,10 @@ C++23 Feature Support
functions. Which include allowing non-literal types as return values and parameters, allow calling of
non-constexpr functions and constructors.
+C++2c Feature Support
+^^^^^^^^^^^^^^^^^^^^^
+- Compiler flags ``-std=c++2c`` and ``-std=gnu++2c`` have been added for experimental C++2c implementation work.
+
Resolutions to C++ Defect Reports
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Implemented `DR2397 <https://wg21.link/CWG2397>`_ which allows ``auto`` specifier for pointers
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 1a792f1cf6e8b..08b8f02460c16 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -307,6 +307,11 @@ def : DiagGroup<"c++98-c++11-c++14-c++17-compat-pedantic",
def CXXPre23Compat : DiagGroup<"pre-c++23-compat">;
def CXXPre23CompatPedantic :
DiagGroup<"pre-c++23-compat-pedantic", [CXXPre23Compat]>;
+def CXXPre26Compat : DiagGroup<"pre-c++26-compat">;
+def CXXPre26CompatPedantic :
+ DiagGroup<"pre-c++26-compat-pedantic", [CXXPre26Compat]>;
+def : DiagGroup<"pre-c++2c-compat", [CXXPre26Compat]>;
+def : DiagGroup<"pre-c++2c-compat-pedantic", [CXXPre26CompatPedantic]>;
def CXX98CompatBindToTemporaryCopy :
DiagGroup<"c++98-compat-bind-to-temporary-copy">;
@@ -1112,11 +1117,16 @@ def CXX20 : DiagGroup<"c++20-extensions", [CXX20Designator, CXX20Attrs]>;
// earlier C++ versions.
def CXX23 : DiagGroup<"c++23-extensions">;
+// A warning group for warnings about using C++26 features as extensions in
+// earlier C++ versions.
+def CXX26 : DiagGroup<"c++26-extensions">;
+
def : DiagGroup<"c++0x-extensions", [CXX11]>;
def : DiagGroup<"c++1y-extensions", [CXX14]>;
def : DiagGroup<"c++1z-extensions", [CXX17]>;
def : DiagGroup<"c++2a-extensions", [CXX20]>;
def : DiagGroup<"c++2b-extensions", [CXX23]>;
+def : DiagGroup<"c++2c-extensions", [CXX26]>;
def DelegatingCtorCycles :
DiagGroup<"delegating-ctor-cycles">;
diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def
index 495b17e769e5d..95cd6959cfb52 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -98,6 +98,7 @@ LANGOPT(CPlusPlus14 , 1, 0, "C++14")
LANGOPT(CPlusPlus17 , 1, 0, "C++17")
LANGOPT(CPlusPlus20 , 1, 0, "C++20")
LANGOPT(CPlusPlus23 , 1, 0, "C++23")
+LANGOPT(CPlusPlus26 , 1, 0, "C++26")
LANGOPT(ObjC , 1, 0, "Objective-C")
BENIGN_LANGOPT(ObjCDefaultSynthProperties , 1, 0,
"Objective-C auto-synthesized properties")
diff --git a/clang/include/clang/Basic/LangStandard.h b/clang/include/clang/Basic/LangStandard.h
index ebe14c8a3f8fd..fd949bcd68555 100644
--- a/clang/include/clang/Basic/LangStandard.h
+++ b/clang/include/clang/Basic/LangStandard.h
@@ -56,11 +56,12 @@ enum LangFeatures {
CPlusPlus17 = (1 << 8),
CPlusPlus20 = (1 << 9),
CPlusPlus23 = (1 << 10),
- Digraphs = (1 << 11),
- GNUMode = (1 << 12),
- HexFloat = (1 << 13),
- OpenCL = (1 << 14),
- HLSL = (1 << 15)
+ CPlusPlus26 = (1 << 11),
+ Digraphs = (1 << 12),
+ GNUMode = (1 << 13),
+ HexFloat = (1 << 14),
+ OpenCL = (1 << 15),
+ HLSL = (1 << 16)
};
/// LangStandard - Information about the properties of a particular language
@@ -121,6 +122,9 @@ struct LangStandard {
/// isCPlusPlus23 - Language is a post-C++23 variant (or later).
bool isCPlusPlus23() const { return Flags & CPlusPlus23; }
+ /// isCPlusPlus26 - Language is a post-C++26 variant (or later).
+ bool isCPlusPlus26() const { return Flags & CPlusPlus26; }
+
/// hasDigraphs - Language supports digraphs.
bool hasDigraphs() const { return Flags & Digraphs; }
diff --git a/clang/include/clang/Basic/LangStandards.def b/clang/include/clang/Basic/LangStandards.def
index 8e4d3759f33b7..911b626e4c966 100644
--- a/clang/include/clang/Basic/LangStandards.def
+++ b/clang/include/clang/Basic/LangStandards.def
@@ -163,6 +163,18 @@ LANGSTANDARD(gnucxx23, "gnu++23",
CPlusPlus20 | CPlusPlus23 | Digraphs | HexFloat | GNUMode)
LANGSTANDARD_ALIAS_DEPR(gnucxx23, "gnu++2b")
+LANGSTANDARD(cxx26, "c++2c",
+ CXX, "Working draft for C++2c",
+ LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 |
+ CPlusPlus20 | CPlusPlus23 | CPlusPlus26 | Digraphs | HexFloat)
+LANGSTANDARD_ALIAS(cxx26, "c++26")
+
+LANGSTANDARD(gnucxx26, "gnu++2c",
+ CXX, "Working draft for C++2c with GNU extensions",
+ LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 |
+ CPlusPlus20 | CPlusPlus23 | CPlusPlus26 | Digraphs | HexFloat | GNUMode)
+LANGSTANDARD_ALIAS(gnucxx26, "gnu++26")
+
// OpenCL
LANGSTANDARD(opencl10, "cl1.0",
OpenCL, "OpenCL 1.0",
diff --git a/clang/lib/Basic/LangOptions.cpp b/clang/lib/Basic/LangOptions.cpp
index 1abbaa9e4b2b4..b44c71f572bee 100644
--- a/clang/lib/Basic/LangOptions.cpp
+++ b/clang/lib/Basic/LangOptions.cpp
@@ -118,6 +118,7 @@ void LangOptions::setLangDefaults(LangOptions &Opts, Language Lang,
Opts.CPlusPlus17 = Std.isCPlusPlus17();
Opts.CPlusPlus20 = Std.isCPlusPlus20();
Opts.CPlusPlus23 = Std.isCPlusPlus23();
+ Opts.CPlusPlus26 = Std.isCPlusPlus26();
Opts.GNUMode = Std.isGNUMode();
Opts.GNUCVersion = 0;
Opts.HexFloats = Std.hasHexFloats();
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 535d9c9de13d2..8fb9975b8404e 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1397,6 +1397,7 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
!Args.hasArg(options::OPT_fmodules) && Std &&
(Std->containsValue("c++20") || Std->containsValue("c++2a") ||
Std->containsValue("c++23") || Std->containsValue("c++2b") ||
+ Std->containsValue("c++26") || Std->containsValue("c++2c") ||
Std->containsValue("c++latest"));
// Process -fmodule-header{=} flags.
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 31f2881be6b62..383984e59034e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3674,6 +3674,7 @@ static bool RenderModulesOptions(Compilation &C, const Driver &D,
IsCXX && Std &&
(Std->containsValue("c++2a") || Std->containsValue("c++20") ||
Std->containsValue("c++2b") || Std->containsValue("c++23") ||
+ Std->containsValue("c++2c") || Std->containsValue("c++26") ||
Std->containsValue("c++latest"));
bool HaveModules = HaveStdCXXModules;
@@ -6660,8 +6661,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
.Case("c++14", "-std=c++14")
.Case("c++17", "-std=c++17")
.Case("c++20", "-std=c++20")
- // TODO add c++23 when MSVC supports it.
- .Case("c++latest", "-std=c++23")
+ // TODO add c++23 and c++26 when MSVC supports it.
+ .Case("c++latest", "-std=c++26")
.Default("");
if (LanguageStandard.empty())
D.Diag(clang::diag::warn_drv_unused_argument)
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index 822109c389360..8082a1924802b 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -451,7 +451,10 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
Builder.defineMacro("__STDC_VERSION__", "199409L");
} else {
// -- __cplusplus
- if (LangOpts.CPlusPlus23)
+ if (LangOpts.CPlusPlus26)
+ // FIXME: Use correct value for C++26.
+ Builder.defineMacro("__cplusplus", "202400L");
+ else if (LangOpts.CPlusPlus23)
Builder.defineMacro("__cplusplus", "202302L");
// [C++20] The integer literal 202002L.
else if (LangOpts.CPlusPlus20)
diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index b32b44ab31648..12d7023bd61b1 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -604,7 +604,7 @@
// STDCXX20: -std=c++20
// RUN: %clang_cl -fmsc-version=1900 -TP -std:c++latest -### -- %s 2>&1 | FileCheck -check-prefix=STDCXXLATEST %s
-// STDCXXLATEST: -std=c++23
+// STDCXXLATEST: -std=c++26
// RUN: env CL="/Gy" %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=ENV-CL %s
// ENV-CL: "-ffunction-sections"
diff --git a/clang/test/Driver/unknown-std.cpp b/clang/test/Driver/unknown-std.cpp
index 1490e9e3a1164..e918c087095ef 100644
--- a/clang/test/Driver/unknown-std.cpp
+++ b/clang/test/Driver/unknown-std.cpp
@@ -19,6 +19,8 @@
// CHECK-NEXT: note: use 'gnu++20' for 'ISO C++ 2020 DIS with GNU extensions' standard
// CHECK-NEXT: note: use 'c++23' for 'ISO C++ 2023 DIS' standard
// CHECK-NEXT: note: use 'gnu++23' for 'ISO C++ 2023 DIS with GNU extensions' standard
+// CHECK-NEXT: note: use 'c++2c' or 'c++26' for 'Working draft for C++2c' standard
+// CHECK-NEXT: note: use 'gnu++2c' or 'gnu++26' for 'Working draft for C++2c with GNU extensions' standard
// CUDA-NEXT: note: use 'cuda' for 'NVIDIA CUDA(tm)' standard
// Make sure that no other output is present.
diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 661808e34c872..a45a22b7008ca 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -8,6 +8,15 @@
// BLOCKS:#define __BLOCKS__ 1
// BLOCKS:#define __block __attribute__((__blocks__(byref)))
//
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++26 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX26 %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++2c -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX26 %s
+//
+// CXX26:#define __GNUG__ 4
+// CXX26:#define __GXX_EXPERIMENTAL_CXX0X__ 1
+// CXX26:#define __GXX_RTTI 1
+// CXX26:#define __GXX_WEAK__ 1
+// CXX26:#define __cplusplus 202402L
+// CXX26:#define __private_extern__ extern
//
// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++23 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX2B %s
// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++2b -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX2B %s
@@ -134,6 +143,14 @@
// RUN: %clang_cc1 -ffreestanding -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix FREESTANDING %s
// FREESTANDING:#define __STDC_HOSTED__ 0
//
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++26 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX26 %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++2c -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX26 %s
+//
+// GXX26:#define __GNUG__ 4
+// GXX26:#define __GXX_WEAK__ 1
+// GXX26:#define __cplusplus 202402L
+// GXX26:#define __private_extern__ extern
+//
// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++23 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX2B %s
// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++2b -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX2B %s
//
diff --git a/clang/www/OpenProjects.html b/clang/www/OpenProjects.html
index d3aedd281121c..7a8bdbd3dbbc8 100755
--- a/clang/www/OpenProjects.html
+++ b/clang/www/OpenProjects.html
@@ -123,7 +123,7 @@ <h1>Open Clang Projects</h1>
</ul>
</li>
-<li><b>Continue work on C++20, C++23, and C2x support</b>:
+<li><b>Continue work on C++20, C++23, C++2c, and C2x support</b>:
There are still several C++20 features to complete, and work has begun on
supporting the latest language standards. Please see the
<a href="cxx_status.html">C++ status report page</a> to find out what is
diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index dd45b3c2418cf..564c3d6a8c48c 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -65,6 +65,11 @@ <h1>C++ Support in Clang</h1>
<td><tt>-std=c++23</tt></td>
<td class="partial" align="center">Partial</td>
</tr>
+<tr>
+ <td><a href="#cxx26">C++2c</a></td>
+ <td><tt>-std=c++2c</tt></td>
+ <td class="partial" align="center">Partial</td>
+</tr>
</table>
<p>The Clang community is continually striving to improve C++ standards
@@ -1560,6 +1565,25 @@ <h2 id="cxx23">C++23 implementation status</h2>
</table>
</details>
+<h2 id="cxx26">C++2c implementation status</h2>
+
+<!-- TODO add link to the ISO Standard after it's published. -->
+<p>Clang has support for some of the features of the C++ standard following
+C++23, informally referred to as C++26.</p>
+
+<p>You can use Clang in C++2c mode with the <code>-std=c++2c</code> option.</p>
+
+<details open>
+<summary>List of features and minimum Clang version with support</summary>
+<table width="689" border="1" cellspacing="0">
+ <tr>
+ <th>Language Feature</th>
+ <th>C++26 Proposal</th>
+ <th>Available in Clang?</th>
+ </tr>
+ </table>
+ </details>
+
<h2 id="dr">Defect reports</h2>
<p>Clang generally aims to implement resolutions to Defect Reports (bug fixes
More information about the cfe-commits
mailing list