It seems prudent to add C++26 now that the first C++26 papers have been
approved.  I followed commit r11-6920 as well as r8-3237.

I was puzzled to see that -std=c++23 was marked Undocumented but
-std=c++2b wasn't.  I think it should be the other way round, like
the earlier modes.

As for __cplusplus, I've arbitrarily chosen 202600L:

  $ xg++ -std=c++26 -dM -E -x c++ - < /dev/null | grep cplusplus
  #define __cplusplus 202600L

I've verified the patch with a simple test, exercising the new
directives.  Don't forget to update your GXX_TESTSUITE_STDS!

This patch does not add -Wc++26-extensions.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

gcc/c-family/ChangeLog:

        * c-common.h (cxx_dialect): Add cxx26 as a dialect.
        * c-opts.cc (set_std_cxx26): New.
        (c_common_handle_option): Set options when -std={c,gnu}++2{c,6} is
        enabled.
        (c_common_post_options): Adjust comments.
        * c.opt: Add options for -std=c++26, std=c++2c, -std=gnu++26,
        and -std=gnu++2c.
        (std=c++2b): Mark as Undocumented.
        (std=c++23): No longer Undocumented.

gcc/ChangeLog:

        * doc/cpp.texi (__cplusplus): Document value for -std=c++26 and
        -std=gnu++26.
        * doc/invoke.texi: Document -std=c++26 and -std=gnu++26.
        * dwarf2out.cc (highest_c_language): Handle GNU C++26.
        (gen_compile_unit_die): Likewise.

libcpp/ChangeLog:

        * include/cpplib.h (c_lang): Add CXX26 and GNUCXX26.
        * init.cc (lang_defaults): Add rows for CXX26 and GNUCXX26.
        (cpp_init_builtins): Set __cplusplus to 202600L for C++26.

gcc/testsuite/ChangeLog:

        * lib/target-supports.exp (check_effective_target_c++23): Return
        1 also if check_effective_target_c++26.
        (check_effective_target_c++23_down): New.
        (check_effective_target_c++26_only): New.
        (check_effective_target_c++26): New.
        * g++.dg/cpp26/cplusplus.C: New test.
---
 gcc/c-family/c-common.h                |  4 +++-
 gcc/c-family/c-opts.cc                 | 28 +++++++++++++++++++++++-
 gcc/c-family/c.opt                     | 24 +++++++++++++++++----
 gcc/doc/cpp.texi                       |  5 +++++
 gcc/doc/invoke.texi                    | 12 +++++++++++
 gcc/dwarf2out.cc                       |  5 ++++-
 gcc/testsuite/g++.dg/cpp26/cplusplus.C |  5 +++++
 gcc/testsuite/lib/target-supports.exp  | 30 +++++++++++++++++++++++++-
 libcpp/include/cpplib.h                |  2 +-
 libcpp/init.cc                         | 13 ++++++++---
 10 files changed, 116 insertions(+), 12 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp26/cplusplus.C

diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 336a09f4a40..b5ef5ff6b2c 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -740,7 +740,9 @@ enum cxx_dialect {
   /* C++20 */
   cxx20,
   /* C++23 */
-  cxx23
+  cxx23,
+  /* C++26 */
+  cxx26
 };
 
 /* The C++ dialect being used. C++98 is the default.  */
diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
index c68a2a27469..af19140e382 100644
--- a/gcc/c-family/c-opts.cc
+++ b/gcc/c-family/c-opts.cc
@@ -111,6 +111,7 @@ static void set_std_cxx14 (int);
 static void set_std_cxx17 (int);
 static void set_std_cxx20 (int);
 static void set_std_cxx23 (int);
+static void set_std_cxx26 (int);
 static void set_std_c89 (int, int);
 static void set_std_c99 (int);
 static void set_std_c11 (int);
@@ -663,6 +664,12 @@ c_common_handle_option (size_t scode, const char *arg, 
HOST_WIDE_INT value,
        set_std_cxx23 (code == OPT_std_c__23 /* ISO */);
       break;
 
+    case OPT_std_c__26:
+    case OPT_std_gnu__26:
+      if (!preprocessing_asm_p)
+       set_std_cxx26 (code == OPT_std_c__26 /* ISO */);
+      break;
+
     case OPT_std_c90:
     case OPT_std_iso9899_199409:
       if (!preprocessing_asm_p)
@@ -1032,7 +1039,8 @@ c_common_post_options (const char **pfilename)
        warn_narrowing = 1;
 
       /* Unless -f{,no-}ext-numeric-literals has been used explicitly,
-        for -std=c++{11,14,17,20,23} default to -fno-ext-numeric-literals.  */
+        for -std=c++{11,14,17,20,23,26} default to
+        -fno-ext-numeric-literals.  */
       if (flag_iso && !OPTION_SET_P (flag_ext_numeric_literals))
        cpp_opts->ext_numeric_literals = 0;
     }
@@ -1820,6 +1828,24 @@ set_std_cxx23 (int iso)
   lang_hooks.name = "GNU C++23";
 }
 
+/* Set the C++ 2026 standard (without GNU extensions if ISO).  */
+static void
+set_std_cxx26 (int iso)
+{
+  cpp_set_lang (parse_in, iso ? CLK_CXX26: CLK_GNUCXX26);
+  flag_no_gnu_keywords = iso;
+  flag_no_nonansi_builtin = iso;
+  flag_iso = iso;
+  /* C++26 includes the C11 standard library.  */
+  flag_isoc94 = 1;
+  flag_isoc99 = 1;
+  flag_isoc11 = 1;
+  /* C++26 includes coroutines.  */
+  flag_coroutines = true;
+  cxx_dialect = cxx26;
+  lang_hooks.name = "GNU C++26";
+}
+
 /* Args to -d specify what to dump.  Silently ignore
    unrecognized options; they may be aimed at toplev.cc.  */
 static void
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 0930a3c0422..bc03ebdad97 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -2403,13 +2403,21 @@ C++ ObjC++
 Conform to the ISO 2020 C++ standard (experimental and incomplete support).
 
 std=c++2b
-C++ ObjC++ Alias(std=c++23)
+C++ ObjC++ Alias(std=c++23) Undocumented
 Conform to the ISO 2023 C++ draft standard (experimental and incomplete 
support).
 
 std=c++23
-C++ ObjC++ Undocumented
+C++ ObjC++
 Conform to the ISO 2023 C++ draft standard (experimental and incomplete 
support).
 
+std=c++2c
+C++ ObjC++ Alias(std=c++26) Undocumented
+Conform to the ISO 2026 C++ draft standard (experimental and incomplete 
support).
+
+std=c++26
+C++ ObjC++
+Conform to the ISO 2026 C++ draft standard (experimental and incomplete 
support).
+
 std=c11
 C ObjC
 Conform to the ISO 2011 C standard.
@@ -2489,13 +2497,21 @@ C++ ObjC++
 Conform to the ISO 2020 C++ standard with GNU extensions (experimental and 
incomplete support).
 
 std=gnu++2b
-C++ ObjC++ Alias(std=gnu++23)
+C++ ObjC++ Alias(std=gnu++23) Undocumented
 Conform to the ISO 2023 C++ draft standard with GNU extensions (experimental 
and incomplete support).
 
 std=gnu++23
-C++ ObjC++ Undocumented
+C++ ObjC++
 Conform to the ISO 2023 C++ draft standard with GNU extensions (experimental 
and incomplete support).
 
+std=gnu++2c
+C++ ObjC++ Alias(std=gnu++26) Undocumented
+Conform to the ISO 2026 C++ draft standard with GNU extensions (experimental 
and incomplete support).
+
+std=gnu++26
+C++ ObjC++
+Conform to the ISO 2026 C++ draft standard with GNU extensions (experimental 
and incomplete support).
+
 std=gnu11
 C ObjC
 Conform to the ISO 2011 C standard with GNU extensions.
diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi
index b0a2ce3ac6b..e3e5d2af042 100644
--- a/gcc/doc/cpp.texi
+++ b/gcc/doc/cpp.texi
@@ -1911,6 +1911,11 @@ selected, the value of the macro is
 or an unspecified value strictly larger than @code{202002L} for the
 experimental languages enabled by @option{-std=c++23} and
 @option{-std=gnu++23}.
+Similarly, the value of the macro is an unspecified value strictly
+larger than @code{202002L} (and at the same time strictly larger than
+the unspecified value defined for @option{-std=c++23} above) for the
+experimental languages enabled by @option{-std=c++26} and
+@option{-std=gnu++26}.
 
 @item __OBJC__
 This macro is defined, with value 1, when the Objective-C compiler is in
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index fd4943bf317..efcf3bfb3d6 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -2507,6 +2507,18 @@ change in incompatible ways in future releases.
 GNU dialect of @option{-std=c++2b}.  Support is highly experimental,
 and will almost certainly change in incompatible ways in future
 releases.
+
+@item c++2c
+@itemx c++26
+The next revision of the ISO C++ standard, planned for
+2026.  Support is highly experimental, and will almost certainly
+change in incompatible ways in future releases.
+
+@item gnu++2c
+@itemx gnu++26
+GNU dialect of @option{-std=c++2c}.  Support is highly experimental,
+and will almost certainly change in incompatible ways in future
+releases.
 @end table
 
 @opindex aux-info
diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index e70c47cec8d..9112fc0c64b 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -25105,6 +25105,8 @@ static char *producer_string;
 static const char *
 highest_c_language (const char *lang1, const char *lang2)
 {
+  if (strcmp ("GNU C++26", lang1) == 0 || strcmp ("GNU C++26", lang2) == 0)
+    return "GNU C++26";
   if (strcmp ("GNU C++23", lang1) == 0 || strcmp ("GNU C++23", lang2) == 0)
     return "GNU C++23";
   if (strcmp ("GNU C++20", lang1) == 0 || strcmp ("GNU C++20", lang2) == 0)
@@ -25215,7 +25217,8 @@ gen_compile_unit_die (const char *filename)
            language = DW_LANG_C_plus_plus_14;
          else if (strcmp (language_string, "GNU C++17") == 0
                   || strcmp (language_string, "GNU C++20") == 0
-                  || strcmp (language_string, "GNU C++23") == 0)
+                  || strcmp (language_string, "GNU C++23") == 0
+                  || strcmp (language_string, "GNU C++26") == 0)
            /* For now.  */
            language = DW_LANG_C_plus_plus_14;
        }
diff --git a/gcc/testsuite/g++.dg/cpp26/cplusplus.C 
b/gcc/testsuite/g++.dg/cpp26/cplusplus.C
new file mode 100644
index 00000000000..3027f9e711a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp26/cplusplus.C
@@ -0,0 +1,5 @@
+// { dg-do compile }
+// { dg-options "-std=c++26" }
+
+// TODO: Update once __cplusplus is defined for C++23.
+static_assert(__cplusplus > 202002L);
diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index d79ad4be105..c04db2be7f9 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -10785,7 +10785,35 @@ proc check_effective_target_c++23_only { } {
     return 0
 }
 proc check_effective_target_c++23 { } {
-    return [check_effective_target_c++23_only]
+    if [check_effective_target_c++23_only] {
+       return 1
+    }
+    return [check_effective_target_c++26]
+}
+
+proc check_effective_target_c++23_down { } {
+    if ![check_effective_target_c++] {
+       return 0
+    }
+    return [expr ![check_effective_target_c++26] ]
+}
+
+proc check_effective_target_c++26_only { } {
+    global cxx_default
+    if ![check_effective_target_c++] {
+       return 0
+    }
+    if [check-flags { { } { } { -std=c++26 -std=gnu++26 -std=c++2c 
-std=gnu++2c } }] {
+       return 1
+    }
+    if { $cxx_default == "c++26" && [check-flags { { } { } { } { -std=* } }] } 
{
+       return 1
+    }
+    return 0
+}
+
+proc check_effective_target_c++26 { } {
+    return [check_effective_target_c++26_only]
 }
 
 # Check for C++ Concepts support, i.e. -fconcepts flag.
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index d326f5aa316..aef703f8111 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -174,7 +174,7 @@ enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_GNUC11, 
CLK_GNUC17, CLK_GNUC2X,
             CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11,
             CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX17, CLK_CXX17,
             CLK_GNUCXX20, CLK_CXX20, CLK_GNUCXX23, CLK_CXX23,
-            CLK_ASM};
+            CLK_GNUCXX26, CLK_CXX26, CLK_ASM};
 
 /* Payload of a NUMBER, STRING, CHAR or COMMENT token.  */
 struct GTY(()) cpp_string {
diff --git a/libcpp/init.cc b/libcpp/init.cc
index c508f06112a..8ef8833e508 100644
--- a/libcpp/init.cc
+++ b/libcpp/init.cc
@@ -127,6 +127,8 @@ static const struct lang_flags lang_defaults[] =
   /* CXX20    */  { 1,  1,  1,  1,  1,  1,    1,  1,   1,   1,   1,    1,     
1,     0,   1,      1,   1,     0,   0,   0,      0,      0,    1 },
   /* GNUCXX23 */  { 1,  1,  1,  1,  1,  1,    0,  1,   1,   1,   1,    1,     
1,     0,   1,      1,   1,     0,   1,   1,      1,      1,    1 },
   /* CXX23    */  { 1,  1,  1,  1,  1,  1,    1,  1,   1,   1,   1,    1,     
1,     0,   1,      1,   1,     0,   1,   1,      1,      1,    1 },
+  /* GNUCXX26 */  { 1,  1,  1,  1,  1,  1,    0,  1,   1,   1,   1,    1,     
1,     0,   1,      1,   1,     0,   1,   1,      1,      1,    1 },
+  /* CXX26    */  { 1,  1,  1,  1,  1,  1,    1,  1,   1,   1,   1,    1,     
1,     0,   1,      1,   1,     0,   1,   1,      1,      1,    1 },
   /* ASM      */  { 0,  0,  1,  0,  0,  0,    0,  0,   0,   0,   0,    0,     
0,     0,   0,      0,   0,     0,   0,   0,      0,      0,    0 }
 };
 
@@ -561,9 +563,14 @@ cpp_init_builtins (cpp_reader *pfile, int hosted)
 
   if (CPP_OPTION (pfile, cplusplus))
     {
-      /* C++23 is not yet a standard.  For now, use an invalid
-       * year/month, 202100L, which is larger than 202002L.  */
-      if (CPP_OPTION (pfile, lang) == CLK_CXX23
+      /* C++26 is not yet a standard.  For now, use an invalid
+        year/month, 202600L, which is larger than 202100L.  */
+      if (CPP_OPTION (pfile, lang) == CLK_CXX26
+         || CPP_OPTION (pfile, lang) == CLK_GNUCXX26)
+       _cpp_define_builtin (pfile, "__cplusplus 202600L");
+      /* C++23 is not yet a standard, either.  For now, use an invalid
+        year/month, 202100L, which is larger than 202002L.  */
+      else if (CPP_OPTION (pfile, lang) == CLK_CXX23
          || CPP_OPTION (pfile, lang) == CLK_GNUCXX23)
        _cpp_define_builtin (pfile, "__cplusplus 202100L");
       else if (CPP_OPTION (pfile, lang) == CLK_CXX20

base-commit: 33ebb0dff9bb022f1e0709e0e73faabfc3df7931
-- 
2.41.0

Reply via email to