]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: add missing -Wc++??-extensions checks
authorJason Merrill <jason@redhat.com>
Tue, 27 Aug 2024 17:14:45 +0000 (13:14 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 28 Aug 2024 09:52:12 +0000 (05:52 -0400)
The pedwarns for each of these features should be silenced by
the appropriate -Wno-c++??-extensions.

The handle_pragma_diagnostic_impl change is necessary so that we handle
-Wc++23-extensions early so it's available to interpret_float while lexing.

gcc/c-family/ChangeLog:

* c-pragma.cc (handle_pragma_diagnostic_impl): Also handle
-Wc++23-extensions early.
* c-lex.cc (interpret_float): Use -Wc++23-extensions for extended
floating point literal pedwarn.

gcc/cp/ChangeLog:

* parser.cc (cp_parser_simple_type_specifier): Use
-Wc++20-extensions for auto parameter pedwarn.
* pt.cc (do_decl_instantiation, do_type_instantiation): Use
-Wc++11-extensions for 'extern template'.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/extern_template-7.C: New test.
* g++.dg/cpp23/ext-floating19.C: New test.
* g++.dg/cpp2a/abbrev-fn1.C: New test.

gcc/c-family/c-lex.cc
gcc/c-family/c-pragma.cc
gcc/cp/parser.cc
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp0x/extern_template-7.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/ext-floating19.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/abbrev-fn1.C [new file with mode: 0644]

index ff5ce2bf729a7135d5272f14963936895e3a2baf..d99d8ea2c0c5555a592771737b27e0762e956672 100644 (file)
@@ -1254,8 +1254,8 @@ interpret_float (const cpp_token *token, unsigned int flags,
          }
        else if (!extended)
          {
-           if (cxx_dialect < cxx23)
-             pedwarn (input_location, OPT_Wpedantic,
+           if (cxx_dialect < cxx23 && pedantic)
+             pedwarn (input_location, OPT_Wc__23_extensions,
                       "%<f%d%> or %<F%d%> suffix on floating constant only "
                       "available with %<-std=c++2b%> or %<-std=gnu++2b%>",
                       n, n);
@@ -1275,8 +1275,8 @@ interpret_float (const cpp_token *token, unsigned int flags,
        if (!c_dialect_cxx ())
          pedwarn (input_location, OPT_Wpedantic,
                   "non-standard suffix on floating constant");
-       else if (cxx_dialect < cxx23)
-         pedwarn (input_location, OPT_Wpedantic,
+       else if (cxx_dialect < cxx23 && pedantic)
+         pedwarn (input_location, OPT_Wc__23_extensions,
                   "%<bf16%> or %<BF16%> suffix on floating constant only "
                   "available with %<-std=c++2b%> or %<-std=gnu++2b%>");
       }
index ed2a7a00e9eb9233c086dec6e6d157ff49c91124..bb867eb995aa0c910ff419dbb5f1ad50c0524069 100644 (file)
@@ -964,6 +964,8 @@ handle_pragma_diagnostic_impl ()
   unsigned int option_index = find_opt (data.option_str + 1, lang_mask);
 
   if (early && !(c_option_is_from_cpp_diagnostics (option_index)
+                /* For interpret_float.  */
+                || option_index == OPT_Wc__23_extensions
                 || option_index == OPT_Wunknown_pragmas))
     return;
 
index a722641be347605dcf38126b8b59b2c6ff335dac..918072dbf637493895cceefb6f8fed16e2153657 100644 (file)
@@ -20527,7 +20527,7 @@ cp_parser_simple_type_specifier (cp_parser* parser,
            error_at (token->location,
                     "use of %<auto%> in template argument");
          else if (!flag_concepts)
-           pedwarn (token->location, 0,
+           pedwarn (token->location, OPT_Wc__20_extensions,
                     "use of %<auto%> in parameter declaration "
                     "only available with %<-std=c++20%> or %<-fconcepts%>");
          else if (cxx_dialect < cxx14)
index 24a6241d3a5124caf7aba7dc31a726968862c2d3..9e0f0486ffbc2aa514d16a69bdbd7369c20acbef 100644 (file)
@@ -26531,8 +26531,8 @@ do_decl_instantiation (tree decl, tree storage)
     ;
   else if (storage == ridpointers[(int) RID_EXTERN])
     {
-      if (cxx_dialect == cxx98)
-       pedwarn (input_location, OPT_Wpedantic,
+      if (cxx_dialect == cxx98 && pedantic)
+       pedwarn (input_location, OPT_Wc__11_extensions,
                 "ISO C++ 1998 forbids the use of %<extern%> on explicit "
                 "instantiations");
       extern_p = 1;
@@ -26598,8 +26598,8 @@ do_type_instantiation (tree t, tree storage, tsubst_flags_t complain)
     {
       if (storage == ridpointers[(int) RID_EXTERN])
        {
-         if (cxx_dialect == cxx98)
-           pedwarn (input_location, OPT_Wpedantic,
+         if (cxx_dialect == cxx98 && pedantic)
+           pedwarn (input_location, OPT_Wc__11_extensions,
                     "ISO C++ 1998 forbids the use of %<extern%> on "
                     "explicit instantiations");
        }
diff --git a/gcc/testsuite/g++.dg/cpp0x/extern_template-7.C b/gcc/testsuite/g++.dg/cpp0x/extern_template-7.C
new file mode 100644 (file)
index 0000000..0a0431f
--- /dev/null
@@ -0,0 +1,10 @@
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wc++11-extensions"
+
+template <class T> struct A
+{
+  void f() { }
+};
+
+extern template class A<int>;
+extern template void A<char>::f();
diff --git a/gcc/testsuite/g++.dg/cpp23/ext-floating19.C b/gcc/testsuite/g++.dg/cpp23/ext-floating19.C
new file mode 100644 (file)
index 0000000..dfbedb9
--- /dev/null
@@ -0,0 +1,20 @@
+// { dg-do compile { target c++11 } }
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wc++23-extensions"
+
+#ifdef __STDCPP_FLOAT16_T__
+auto x16 = 3.14f16;
+#endif
+#ifdef __STDCPP_FLOAT32_T__
+auto x32 = 3.14f32;
+#endif
+#ifdef __STDCPP_FLOAT64_T__
+auto x64 = 3.14f64;
+#endif
+#ifdef __STDCPP_FLOAT128_T__
+auto x128 = 3.14f128;
+#endif
+#ifdef __STDCPP_FLOAT16_T__
+auto xbf = 1.2bf16;
+#endif
diff --git a/gcc/testsuite/g++.dg/cpp2a/abbrev-fn1.C b/gcc/testsuite/g++.dg/cpp2a/abbrev-fn1.C
new file mode 100644 (file)
index 0000000..ca25308
--- /dev/null
@@ -0,0 +1,6 @@
+// { dg-do compile { target c++11 } }
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wc++20-extensions"
+
+void f(auto p) { }