On 2/27/25 11:37 AM, Jakub Jelinek wrote:
On Thu, Feb 27, 2025 at 10:48:14AM -0500, Jason Merrill wrote:
--- libcpp/directives.cc.jj     2025-02-13 19:59:56.202572170 +0100
+++ libcpp/directives.cc        2025-02-20 21:40:56.379899457 +0100
@@ -1367,7 +1367,7 @@ do_embed (cpp_reader *pfile)
       {
         if (CPP_OPTION (pfile, cplusplus))
        cpp_error (pfile, CPP_DL_PEDWARN,
-                  "%<#%s%> is a GCC extension", "embed");
+                  "%<#%s%> before C++26 is a GCC extension", "embed");

Please change this to cpp_pedwarning/CPP_W_CXX26_EXTENSIONS.

Ok.  I've changed it for C as well and added a -Wc11-c23-compat warning
for this as well (like the cpp_pedwarning is used for other preprocessor
extensions).

Here is an updated patch, so far tested with
GXX_TESTSUITE_STDS=98,11,14,17,20,23,26 make check-gcc check-g++ 
RUNTESTFLAGS='dg.exp=*embed* cpp.exp=*embed*'
ok for trunk if it passes full bootstrap/regtest?

OK.

2025-02-27  Jakub Jelinek  <ja...@redhat.com>

libcpp/
        * include/cpplib.h (enum cpp_warning_reason): Add
        CPP_W_CXX26_EXTENSIONS enumerator.
        * init.cc (lang_defaults): Set embed for GNUCXX26 and CXX26.
        * directives.cc (do_embed): Adjust pedwarn wording for embed in C++,
        use cpp_pedwarning instead of cpp_error and add CPP_W_C11_C23_COMPAT
        warning of cpp_pedwarning hasn't diagnosed anything.
gcc/c-family/
        * c.opt (Wc++26-extensions): Add CppReason(CPP_W_CXX26_EXTENSIONS).
        * c-cppbuiltin.cc (c_cpp_builtins): Predefine __cpp_pp_embed=202502
        for C++26.
gcc/testsuite/
        * g++.dg/cpp/embed-1.C: Adjust for pedwarn wording change and don't
        expect any error for C++26.
        * g++.dg/cpp/embed-2.C: Adjust for pedwarn wording change and don't
        expect any warning for C++26.
        * g++.dg/cpp26/feat-cxx26.C: Test __cpp_pp_embed value.
        * gcc.dg/cpp/embed-17.c: New test.

--- libcpp/include/cpplib.h.jj  2025-01-02 11:47:49.482953335 +0100
+++ libcpp/include/cpplib.h     2025-02-27 17:09:20.684244029 +0100
@@ -749,6 +749,7 @@ enum cpp_warning_reason {
    CPP_W_CXX17_EXTENSIONS,
    CPP_W_CXX20_EXTENSIONS,
    CPP_W_CXX23_EXTENSIONS,
+  CPP_W_CXX26_EXTENSIONS,
    CPP_W_EXPANSION_TO_DEFINED,
    CPP_W_BIDIRECTIONAL,
    CPP_W_INVALID_UTF8,
--- libcpp/init.cc.jj   2025-01-02 11:47:49.417954243 +0100
+++ libcpp/init.cc      2025-02-27 17:07:24.319855385 +0100
@@ -149,8 +149,8 @@ static const struct lang_flags lang_defa
    /* CXX20    */ { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,0,0,0,0,0,0,1,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,0,1,0,0,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,0,1,0,0,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,0,1,0,0,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,0,1,0,0,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,0,1,1,0,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,0,1,1,0,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,0,0,0,0,0 }
  };
--- libcpp/directives.cc.jj 2025-01-02 11:47:49.306955792 +0100
+++ libcpp/directives.cc        2025-02-27 17:28:27.421351577 +0100
@@ -1349,7 +1349,7 @@ do_embed (cpp_reader *pfile)
  {
    int angle_brackets;
    struct cpp_embed_params params = {};
-  bool ok;
+  bool ok, warned = false;
    const char *fname = NULL;
/* Tell the lexer this is an embed directive. */
@@ -1366,12 +1366,17 @@ do_embed (cpp_reader *pfile)
    if (CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, embed))
      {
        if (CPP_OPTION (pfile, cplusplus))
-       cpp_error (pfile, CPP_DL_PEDWARN,
-                  "%<#%s%> is a GCC extension", "embed");
+       warned = cpp_pedwarning (pfile, CPP_W_CXX26_EXTENSIONS,
+                                "%<#%s%> before C++26 is a GCC extension",
+                                "embed");
        else
-       cpp_error (pfile, CPP_DL_PEDWARN,
-                  "%<#%s%> before C23 is a GCC extension", "embed");
+       warned = cpp_pedwarning (pfile, CPP_W_PEDANTIC,
+                                "%<#%s%> before C23 is a GCC extension",
+                                "embed");
      }
+  if (!warned && CPP_OPTION (pfile, cpp_warn_c11_c23_compat) > 0)
+    cpp_warning (pfile, CPP_W_C11_C23_COMPAT,
+                "%<#%s%> is a C23 feature", "embed");
fname = parse_include (pfile, &angle_brackets, NULL, &params.loc);
    if (!fname)
--- gcc/c-family/c.opt.jj       2025-02-13 14:10:52.904623608 +0100
+++ gcc/c-family/c.opt  2025-02-27 17:08:33.198901580 +0100
@@ -513,7 +513,7 @@ C++ ObjC++ Var(warn_cxx23_extensions) Wa
  Warn about C++23 constructs in code compiled with an older standard.
Wc++26-extensions
-C++ ObjC++ Var(warn_cxx26_extensions) Warning Init(1)
+C++ ObjC++ Var(warn_cxx26_extensions) Warning Init(1) 
CppReason(CPP_W_CXX26_EXTENSIONS)
  Warn about C++26 constructs in code compiled with an older standard.
Wcalloc-transposed-args
--- gcc/c-family/c-cppbuiltin.cc.jj     2025-01-02 11:47:29.651230200 +0100
+++ gcc/c-family/c-cppbuiltin.cc        2025-02-27 17:07:24.321855358 +0100
@@ -1093,6 +1093,7 @@ c_cpp_builtins (cpp_reader *pfile)
          cpp_define (pfile, "__cpp_deleted_function=202403L");
          cpp_define (pfile, "__cpp_variadic_friend=202403L");
          cpp_define (pfile, "__cpp_pack_indexing=202311L");
+         cpp_define (pfile, "__cpp_pp_embed=202502L");
        }
        if (flag_concepts && cxx_dialect > cxx14)
        cpp_define (pfile, "__cpp_concepts=202002L");
--- gcc/testsuite/g++.dg/cpp/embed-1.C.jj       2024-10-12 10:50:41.057854492 
+0200
+++ gcc/testsuite/g++.dg/cpp/embed-1.C  2025-02-27 17:07:24.724849776 +0100
@@ -6,9 +6,9 @@
  #endif
int a =
-#embed __FILE__ limit (1) // { dg-error "'#embed' is a GCC extension" }
+#embed __FILE__ limit (1) // { dg-error "'#embed' before C\\\+\\\+26 is a GCC extension" 
"" { target c++23_down } }
  ;
  int b =
  (__extension__
-#embed __FILE__ limit (1) // { dg-error "'#embed' is a GCC extension" }
+#embed __FILE__ limit (1) // { dg-error "'#embed' before C\\\+\\\+26 is a GCC extension" 
"" { target c++23_down } }
  );
--- gcc/testsuite/g++.dg/cpp/embed-2.C.jj       2024-10-12 10:50:41.057854492 
+0200
+++ gcc/testsuite/g++.dg/cpp/embed-2.C  2025-02-27 17:07:24.731849680 +0100
@@ -6,9 +6,9 @@
  #endif
int a =
-#embed __FILE__ limit (1) // { dg-warning "'#embed' is a GCC extension" }
+#embed __FILE__ limit (1) // { dg-warning "'#embed' before C\\\+\\\+26 is a GCC 
extension" "" { target c++23_down } }
  ;
  int b =
  (__extension__
-#embed __FILE__ limit (1) // { dg-warning "'#embed' is a GCC extension" }
+#embed __FILE__ limit (1) // { dg-warning "'#embed' before C\\\+\\\+26 is a GCC 
extension" "" { target c++23_down } }
  );
--- gcc/testsuite/g++.dg/cpp26/feat-cxx26.C.jj  2024-11-29 09:28:09.870456136 
+0100
+++ gcc/testsuite/g++.dg/cpp26/feat-cxx26.C     2025-02-27 17:07:24.763849236 
+0100
@@ -628,3 +628,9 @@
  #elif __cpp_pack_indexing != 202311
  #  error "__cpp_pack_indexing != 202311"
  #endif
+
+#ifndef __cpp_pp_embed
+# error "__cpp_pp_embed"
+#elif __cpp_pp_embed != 202502
+#  error "__cpp_pp_embed != 202502"
+#endif
--- gcc/testsuite/gcc.dg/cpp/embed-17.c.jj      2025-02-27 17:20:29.184982436 
+0100
+++ gcc/testsuite/gcc.dg/cpp/embed-17.c 2025-02-27 17:21:01.339536604 +0100
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c23 -Wc11-c23-compat" } */
+
+#if __has_embed (__FILE__ limit (1)) != 1
+#error "__has_embed failed"
+#endif
+
+int a =
+#embed __FILE__ limit (1) /* { dg-warning "'#embed' is a C23 feature" } */
+;
+int b =
+(__extension__
+#embed __FILE__ limit (1)
+);


        Jakub


Reply via email to