diff --git a/clang/docs/CommandGuide/clang.rst b/clang/docs/CommandGuide/clang.rst --- a/clang/docs/CommandGuide/clang.rst +++ b/clang/docs/CommandGuide/clang.rst @@ -201,6 +201,14 @@ ISO C++ 2023 with amendments and GNU extensions + | ``c++2c`` + + ISO C++ Working draft for ISO C++ 2026 + + | ``gnu++2c`` + + ISO Working draft for ISO C++ 2026 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 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -195,6 +195,10 @@ - ``-dumpdir`` has been implemented to specify auxiliary and dump output filenames for features like ``-gsplit-dwarf``. +- The flag ``-std=c++2c`` has been added. This compiles C++ code using the + Working Draft for ISO C++ 2026. + + Deprecated Compiler Flags ------------------------- diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -98,6 +98,7 @@ 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 --- a/clang/include/clang/Basic/LangStandard.h +++ b/clang/include/clang/Basic/LangStandard.h @@ -56,11 +56,12 @@ 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 @@ /// isCPlusPlus23 - Language is a post-C++23 variant (or later). bool isCPlusPlus23() const { return Flags & CPlusPlus23; } + /// isCPlusPlus26 - Language is a post-C++23 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 --- a/clang/include/clang/Basic/LangStandards.def +++ b/clang/include/clang/Basic/LangStandards.def @@ -163,6 +163,18 @@ CPlusPlus20 | CPlusPlus23 | Digraphs | HexFloat | GNUMode) LANGSTANDARD_ALIAS_DEPR(gnucxx23, "gnu++2b") +LANGSTANDARD(cxx26, "c++26", + CXX, "Working draft for ISO C++ 2026 DIS", + LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 | + CPlusPlus20 | CPlusPlus23 | CPlusPlus26 | Digraphs | HexFloat) +LANGSTANDARD_ALIAS_DEPR(cxx26, "c++2c") + +LANGSTANDARD(gnucxx26, "gnu++26", + CXX, "Working draft for ISO C++ 2026 DIS with GNU extensions", + LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 | + CPlusPlus20 | CPlusPlus23 | CPlusPlus26 | Digraphs | HexFloat | GNUMode) +LANGSTANDARD_ALIAS_DEPR(gnucxx26, "gnu++2c") + // OpenCL LANGSTANDARD(opencl10, "cl1.0", OpenCL, "OpenCL 1.0", diff --git a/clang/lib/Basic/LangOptions.cpp b/clang/lib/Basic/LangOptions.cpp --- a/clang/lib/Basic/LangOptions.cpp +++ b/clang/lib/Basic/LangOptions.cpp @@ -118,6 +118,7 @@ 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 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1397,6 +1397,7 @@ !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 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -3674,6 +3674,7 @@ 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; @@ -6646,7 +6647,7 @@ .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") + .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 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -451,8 +451,11 @@ Builder.defineMacro("__STDC_VERSION__", "199409L"); } else { // -- __cplusplus + // FIXME: Use correct value for C++26. + if (LangOpts.CPlusPlus26) + Builder.defineMacro("__cplusplus", "202401L"); // FIXME: Use correct value for C++23. - if (LangOpts.CPlusPlus23) + else if (LangOpts.CPlusPlus23) Builder.defineMacro("__cplusplus", "202101L"); // [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 --- 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 --- 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++26' for 'Working draft for ISO C++ 2026 DIS' standard +// CHECK-NEXT: note: use 'gnu++26' for 'Working draft for ISO C++ 2026 DIS 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 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -9,6 +9,16 @@ // 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 CXX2C %s +// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++2c -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX2C %s +// +// CXX2C:#define __GNUG__ 4 +// CXX2C:#define __GXX_EXPERIMENTAL_CXX0X__ 1 +// CXX2C:#define __GXX_RTTI 1 +// CXX2C:#define __GXX_WEAK__ 1 +// CXX2C:#define __cplusplus 202401L +// CXX2C:#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 // // CXX2B:#define __GNUG__ 4 @@ -133,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 GXX2C %s +// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++2c -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX2C %s +// +// GXX2C:#define __GNUG__ 4 +// GXX2C:#define __GXX_WEAK__ 1 +// GXX2C:#define __cplusplus 202401L +// GXX2C:#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 // // GXX2B:#define __GNUG__ 4