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 @@ -184,6 +184,9 @@ - The flag ``-std=c++23`` has been added. This behaves the same as the existing flag ``-std=c++2b``. +- 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(CPlusPlus2c , 1, 0, "C++2c") 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) + CPlusPlus2c = (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; } + /// isCPlusPlus2c - Language is a post-C++23 variant (or later). + bool isCPlusPlus2c() const { return Flags & CPlusPlus2c; } + /// 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,16 @@ CPlusPlus20 | CPlusPlus23 | Digraphs | HexFloat | GNUMode) LANGSTANDARD_ALIAS_DEPR(gnucxx23, "gnu++2b") +LANGSTANDARD(cxx2c, "c++2c", + CXX, "Working draft for ISO C++ 2026 DIS", + LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 | + CPlusPlus20 | CPlusPlus23 | CPlusPlus2c | Digraphs | HexFloat) + +LANGSTANDARD(gnucxx2c, "gnu++2c", + CXX, "Working draft for ISO C++ 2026 DIS with GNU extensions", + LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 | + CPlusPlus20 | CPlusPlus23 | CPlusPlus2c | Digraphs | HexFloat | GNUMode) + // 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.CPlusPlus2c = Std.isCPlusPlus2c(); 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,7 +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++latest")); + Std->containsValue("c++2c") || Std->containsValue("c++latest")); // Process -fmodule-header{=} flags. if (Arg *A = Args.getLastArg(options::OPT_fmodule_header_EQ, 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,7 +3674,7 @@ IsCXX && Std && (Std->containsValue("c++2a") || Std->containsValue("c++20") || Std->containsValue("c++2b") || Std->containsValue("c++23") || - Std->containsValue("c++latest")); + Std->containsValue("c++2c") || Std->containsValue("c++latest")); bool HaveModules = HaveStdCXXModules; // -fmodules enables the use of precompiled modules (off by default). @@ -6639,7 +6639,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++2c") .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 @@ -438,8 +438,11 @@ // value is, are implementation-defined. // (Removed in C++20.) if (!LangOpts.CPlusPlus) { + // FIXME: Use correct value for C++26. + if (LangOpts.CPlusPlus2c) + Builder.defineMacro("__cplusplus", "202401L"); // FIXME: Use correct value for C23. - if (LangOpts.C2x) + else if (LangOpts.C2x) Builder.defineMacro("__STDC_VERSION__", "202000L"); else if (LangOpts.C17) Builder.defineMacro("__STDC_VERSION__", "201710L"); 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++2c // 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++2c' for 'Working draft for ISO C++ 2026 DIS' standard +// CHECK-NEXT: note: use 'gnu++2c' 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,15 @@ // BLOCKS:#define __block __attribute__((__blocks__(byref))) // // +// 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 +142,13 @@ // 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++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