public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Add new warning options for C++ language mismatches
@ 2021-05-19 16:32 Jonathan Wakely
  2021-05-19 16:39 ` Jonathan Wakely
  2021-05-19 16:40 ` Eric Gallager
  0 siblings, 2 replies; 31+ messages in thread
From: Jonathan Wakely @ 2021-05-19 16:32 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2609 bytes --]

This adds new warning flags, enabled by default: -Wc++11-extensions,
-Wc++14-extensions, -Wc++17-extensions, and -Wc++20-extensions. The
names of the flags are copied from Clang, which already has similar
options.

No new diagnostics are added, but the new OPT_Wxxx variables are used to
control existing pedwarns about occurences of new C++ constructs in code
using an old C++ standard dialect. This allows several existing warnings
that cannot currently be disabled to be controlled by the appropriate
-Wno-xxx flag. For example, it will now be possible to disable warnings
about using variadic templates in C++98 code, by using the new
-Wno-c++11-extensions option. This will allow libstdc++ headers to
disable those warnings unconditionally by using diagnostic pragmas, so
that they are not emitted even if -Wsystem-headers is used.

Some of the affected diagnostics are currently only given when
-Wpedantic is used. Now that we have a more specific warning flag, we
could consider making them not depend on -Wpedantic, and only on the new
flag. This patch does not do that, as it intends to make no changes to
what is accepted/rejected by default. The only effect should be that
the new option is shown when -fdiagnostics-show-option is active, and
that some warnings can be disabled by using the new flags (and for the
warnings that previously only dependend on -Wpedantic, it will now be
possible to disable just those warnings while still using -Wpedantic for
its other benefits).

A new helper function, warn_about_dialect_p, is introduced to avoid the
repetition of `if (cxx_dialect < cxxNN && warn_cxxNN_extensions)`
everywhere.

gcc/c-family/ChangeLog:

	* c.opt (Wc++11-extensions, Wc++14-extensions)
	(Wc++17-extensions, Wc++20-extensions): New options.

gcc/cp/ChangeLog:

	* call.c (maybe_warn_array_conv): Use new function and option.
	* cp-tree.h (warn_about_dialect_p): Declare new function.
	* error.c (maybe_warn_cpp0x): Use new function and options.
	(warn_about_dialect_p): Define new function.
	* parser.c (cp_parser_unqualified_id): Use new function and
	option.
	(cp_parser_pseudo_destructor_name): Likewise.
	(cp_parser_lambda_introducer): Likewise.
	(cp_parser_lambda_declarator_opt): Likewise.
	(cp_parser_init_statement): Likewise.
	(cp_parser_decomposition_declaration): Likewise.
	(cp_parser_function_specifier_opt): Likewise.
	(cp_parser_static_assert): Likewise.
	(cp_parser_namespace_definition): Likewise.
	(cp_parser_initializer_list): Likewise.
	(cp_parser_member_declaration): Likewise.
	* pt.c (check_template_variable): Likewise.

Tested x86_64-linux. OK for trunk?



[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 17656 bytes --]

commit ed749dcee73bff55fc27231c15d2bae265ec86b3
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed May 19 17:07:32 2021

    c++: Add new warning options for C++ language mismatches
    
    This adds new warning flags, enabled by default: -Wc++11-extensions,
    -Wc++14-extensions, -Wc++17-extensions, and -Wc++20-extensions. The
    names of the flags are copied from Clang, which already has similar
    options.
    
    No new diagnostics are added, but the new OPT_Wxxx variables are used to
    control existing pedwarns about occurences of new C++ constructs in code
    using an old C++ standard dialect. This allows several existing warnings
    that cannot currently be disabled to be controlled by the appropriate
    -Wno-xxx flag. For example, it will now be possible to disable warnings
    about using variadic templates in C++98 code, by using the new
    -Wno-c++11-extensions option. This will allow libstdc++ headers to
    disable those warnings unconditionally by using diagnostic pragmas, so
    that they are not emitted even if -Wsystem-headers is used.
    
    Some of the affected diagnostics are currently only given when
    -Wpedantic is used. Now that we have a more specific warning flag, we
    could consider making them not depend on -Wpedantic, and only on the new
    flag. This patch does not do that, as it intends to make no changes to
    what is accepted/rejected by default. The only effect should be that
    the new option is shown when -fdiagnostics-show-option is active, and
    that some warnings can be disabled by using the new flags (and for the
    warnings that previously only dependend on -Wpedantic, it will now be
    possible to disable just those warnings while still using -Wpedantic for
    its other benefits).
    
    A new helper function, warn_about_dialect_p, is introduced to avoid the
    repetition of `if (cxx_dialect < cxxNN && warn_cxxNN_extensions)`
    everywhere.
    
    gcc/c-family/ChangeLog:
    
            * c.opt (Wc++11-extensions, Wc++14-extensions)
            (Wc++17-extensions, Wc++20-extensions): New options.
    
    gcc/cp/ChangeLog:
    
            * call.c (maybe_warn_array_conv): Use new function and option.
            * cp-tree.h (warn_about_dialect_p): Declare new function.
            * error.c (maybe_warn_cpp0x): Use new function and options.
            (warn_about_dialect_p): Define new function.
            * parser.c (cp_parser_unqualified_id): Use new function and
            option.
            (cp_parser_pseudo_destructor_name): Likewise.
            (cp_parser_lambda_introducer): Likewise.
            (cp_parser_lambda_declarator_opt): Likewise.
            (cp_parser_init_statement): Likewise.
            (cp_parser_decomposition_declaration): Likewise.
            (cp_parser_function_specifier_opt): Likewise.
            (cp_parser_static_assert): Likewise.
            (cp_parser_namespace_definition): Likewise.
            (cp_parser_initializer_list): Likewise.
            (cp_parser_member_declaration): Likewise.
            * pt.c (check_template_variable): Likewise.

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 5fcf961fd96..a7605cf3a38 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -431,6 +431,22 @@ Wc++20-compat
 C++ ObjC++ Var(warn_cxx20_compat) Warning LangEnabledBy(C++ ObjC++,Wall)
 Warn about C++ constructs whose meaning differs between ISO C++ 2017 and ISO C++ 2020.
 
+Wc++11-extensions
+C++ ObjC++ Var(warn_cxx11_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
+Warn about C++11 constructs in code compiled with an older standard.
+
+Wc++14-extensions
+C++ ObjC++ Var(warn_cxx14_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
+Warn about C++14 constructs in code compiled with an older standard.
+
+Wc++17-extensions
+C++ ObjC++ Var(warn_cxx17_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
+Warn about C++17 constructs in code compiled with an older standard.
+
+Wc++20-extensions
+C++ ObjC++ Var(warn_cxx20_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
+Warn about C++20 constructs in code compiled with an older standard.
+
 Wcast-function-type
 C ObjC C++ ObjC++ Var(warn_cast_function_type) Warning EnabledBy(Wextra)
 Warn about casts between incompatible function types.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 1e2d1d43184..8b8c685127d 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -7464,8 +7464,10 @@ maybe_warn_array_conv (location_t loc, conversion *c, tree expr)
       || TYPE_DOMAIN (type) == NULL_TREE)
     return;
 
-  if (conv_binds_to_array_of_unknown_bound (c))
-    pedwarn (loc, OPT_Wpedantic, "conversions to arrays of unknown bound "
+  if (conv_binds_to_array_of_unknown_bound (c)
+      && pedantic && warn_about_dialect_p(cxx20))
+    pedwarn (loc, OPT_Wc__20_extensions,
+	     "conversions to arrays of unknown bound "
 	     "are only available with %<-std=c++20%> or %<-std=gnu++20%>");
 }
 
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 580db914d40..f0cf5552437 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -6821,6 +6821,7 @@ extern const char *language_to_string		(enum languages);
 extern const char *class_key_or_enum_as_string	(tree);
 extern void maybe_warn_variadic_templates       (void);
 extern void maybe_warn_cpp0x			(cpp0x_warn_str str);
+extern bool warn_about_dialect_p		(enum cxx_dialect);
 extern bool pedwarn_cxx98                       (location_t, int, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4);
 extern location_t location_of                   (tree);
 extern void qualified_name_lookup_error		(tree, tree, tree,
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 3c2276b1976..794effffd1a 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -4403,81 +4403,82 @@ cp_printer (pretty_printer *pp, text_info *text, const char *spec,
 void
 maybe_warn_cpp0x (cpp0x_warn_str str)
 {
-  if (cxx_dialect == cxx98)
+  if (warn_about_dialect_p(cxx11))
     switch (str)
       {
       case CPP0X_INITIALIZER_LISTS:
-	pedwarn (input_location, 0, 
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "extended initializer lists "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_EXPLICIT_CONVERSION:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "explicit conversion operators "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_VARIADIC_TEMPLATES:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "variadic templates "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_LAMBDA_EXPR:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "lambda expressions "
 		  "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_AUTO:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "C++11 auto only available with %<-std=c++11%> or "
 		 "%<-std=gnu++11%>");
 	break;
       case CPP0X_SCOPED_ENUMS:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "scoped enums only available with %<-std=c++11%> or "
 		 "%<-std=gnu++11%>");
 	break;
       case CPP0X_DEFAULTED_DELETED:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "defaulted and deleted functions "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_INLINE_NAMESPACES:
-	pedwarn (input_location, OPT_Wpedantic,
-		 "inline namespaces "
-		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
+	if (pedantic)
+	  pedwarn (input_location, OPT_Wc__11_extensions,
+		   "inline namespaces "
+		   "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_OVERRIDE_CONTROLS:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "override controls (override/final) "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
         break;
       case CPP0X_NSDMI:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "non-static data member initializers "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
         break;
       case CPP0X_USER_DEFINED_LITERALS:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "user-defined literals "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_DELEGATING_CTORS:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "delegating constructors "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
         break;
       case CPP0X_INHERITING_CTORS:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "inheriting constructors "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
         break;
       case CPP0X_ATTRIBUTES:
-	pedwarn (input_location, 0,
-		 "c++11 attributes "
+	pedwarn (input_location, OPT_Wc__11_extensions,
+		 "C++11 attributes "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_REF_QUALIFIER:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "ref-qualifiers "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
@@ -4493,6 +4494,27 @@ maybe_warn_variadic_templates (void)
   maybe_warn_cpp0x (CPP0X_VARIADIC_TEMPLATES);
 }
 
+/* Whether to warn about constructs from C++ standard DIALECT.  */
+bool
+warn_about_dialect_p(enum cxx_dialect dialect)
+{
+  if (cxx_dialect >= dialect)
+    return false;
+
+  switch (dialect)
+    {
+    case cxx11:
+      return warn_cxx11_extensions;
+    case cxx14:
+      return warn_cxx14_extensions;
+    case cxx17:
+      return warn_cxx17_extensions;
+    case cxx20:
+      return warn_cxx20_extensions;
+    default:
+      gcc_unreachable ();
+    }
+}
 
 /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on
    option OPT with text GMSGID.  Use this function to report
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index c0b57955954..48e37ac5ea2 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -6324,8 +6324,8 @@ cp_parser_unqualified_id (cp_parser* parser,
 	/* ~auto means the destructor of whatever the object is.  */
 	if (cp_parser_is_keyword (token, RID_AUTO))
 	  {
-	    if (cxx_dialect < cxx14)
-	      pedwarn (loc, 0,
+	    if (warn_about_dialect_p(cxx14))
+	      pedwarn (loc, OPT_Wc__14_extensions,
 		       "%<~auto%> only available with "
 		       "%<-std=c++14%> or %<-std=gnu++14%>");
 	    cp_lexer_consume_token (parser->lexer);
@@ -8352,8 +8352,8 @@ cp_parser_pseudo_destructor_name (cp_parser* parser,
       && cp_lexer_nth_token_is_keyword (parser->lexer, 2, RID_AUTO)
       && !type_dependent_expression_p (object))
     {
-      if (cxx_dialect < cxx14)
-	pedwarn (input_location, 0,
+      if (warn_about_dialect_p(cxx14))
+	pedwarn (input_location, OPT_Wc__14_extensions,
 		 "%<~auto%> only available with "
 		 "%<-std=c++14%> or %<-std=gnu++14%>");
       cp_lexer_consume_token (parser->lexer);
@@ -11041,9 +11041,10 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
 	  && cp_lexer_nth_token_is_keyword (parser->lexer, 2, RID_THIS))
 	{
 	  location_t loc = cp_lexer_peek_token (parser->lexer)->location;
-	  if (cxx_dialect < cxx17)
-	    pedwarn (loc, 0, "%<*this%> capture only available with "
-			     "%<-std=c++17%> or %<-std=gnu++17%>");
+	  if (warn_about_dialect_p(cxx17))
+	    pedwarn (loc, OPT_Wc__17_extensions,
+		     "%<*this%> capture only available with "
+		     "%<-std=c++17%> or %<-std=gnu++17%>");
 	  cp_lexer_consume_token (parser->lexer);
 	  cp_lexer_consume_token (parser->lexer);
 	  if (LAMBDA_EXPR_THIS_CAPTURE (lambda_expr))
@@ -11080,8 +11081,9 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
       if (cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS))
 	{
 	  ellipsis_loc = cp_lexer_peek_token (parser->lexer)->location;
-	  if (cxx_dialect < cxx20)
-	    pedwarn (ellipsis_loc, 0, "pack init-capture only available with "
+	  if (warn_about_dialect_p(cxx20))
+	    pedwarn (ellipsis_loc, OPT_Wc__20_extensions,
+		     "pack init-capture only available with "
 		     "%<-std=c++20%> or %<-std=gnu++20%>");
 	  cp_lexer_consume_token (parser->lexer);
 	  init_pack_expansion = true;
@@ -11121,8 +11123,8 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
 	{
 	  bool direct, non_constant;
 	  /* An explicit initializer exists.  */
-	  if (cxx_dialect < cxx14)
-	    pedwarn (input_location, 0,
+	  if (warn_about_dialect_p(cxx14))
+	    pedwarn (input_location, OPT_Wc__14_extensions,
 		     "lambda capture initializers "
 		     "only available with %<-std=c++14%> or %<-std=gnu++14%>");
 	  capture_init_expr = cp_parser_initializer (parser, &direct,
@@ -11295,12 +11297,12 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
      an opening angle if present.  */
   if (cp_lexer_next_token_is (parser->lexer, CPP_LESS))
     {
-      if (cxx_dialect < cxx14)
-	pedwarn (parser->lexer->next_token->location, 0,
+      if (warn_about_dialect_p(cxx14))
+	pedwarn (parser->lexer->next_token->location, OPT_Wc__14_extensions,
 		 "lambda templates are only available with "
 		 "%<-std=c++14%> or %<-std=gnu++14%>");
-      else if (cxx_dialect < cxx20)
-	pedwarn (parser->lexer->next_token->location, OPT_Wpedantic,
+      else if (pedantic && warn_about_dialect_p(cxx20))
+	pedwarn (parser->lexer->next_token->location, OPT_Wc__20_extensions,
 		 "lambda templates are only available with "
 		 "%<-std=c++20%> or %<-std=gnu++20%>");
 
@@ -13421,8 +13423,9 @@ cp_parser_init_statement (cp_parser *parser, tree *decl)
 	  /* It is a range-for, consume the ':'.  */
 	  cp_lexer_consume_token (parser->lexer);
 	  is_range_for = true;
-	  if (cxx_dialect < cxx11)
-	    pedwarn (cp_lexer_peek_token (parser->lexer)->location, 0,
+	  if (warn_about_dialect_p(cxx11))
+	    pedwarn (cp_lexer_peek_token (parser->lexer)->location,
+		     OPT_Wc__11_extensions,
 		     "range-based %<for%> loops only available with "
 		     "%<-std=c++11%> or %<-std=gnu++11%>");
 	}
@@ -14664,9 +14667,10 @@ cp_parser_decomposition_declaration (cp_parser *parser,
 	}
     }
 
-  if (cxx_dialect < cxx17)
-    pedwarn (loc, 0, "structured bindings only available with "
-		     "%<-std=c++17%> or %<-std=gnu++17%>");
+  if (warn_about_dialect_p(cxx17))
+    pedwarn (loc, OPT_Wc__17_extensions,
+	     "structured bindings only available with "
+	     "%<-std=c++17%> or %<-std=gnu++17%>");
 
   tree pushed_scope;
   cp_declarator *declarator = make_declarator (cdk_decomp);
@@ -15260,8 +15264,8 @@ cp_parser_function_specifier_opt (cp_parser* parser,
 	    parser->type_definition_forbidden_message
 	      = G_("types may not be defined in explicit-specifier");
 
-	    if (cxx_dialect < cxx20)
-	      pedwarn (token->location, 0,
+	    if (warn_about_dialect_p(cxx20))
+	      pedwarn (token->location, OPT_Wc__20_extensions,
 		       "%<explicit(bool)%> only available with %<-std=c++20%> "
 		       "or %<-std=gnu++20%>");
 
@@ -15428,8 +15432,8 @@ cp_parser_static_assert(cp_parser *parser, bool member_p)
 
   if (cp_lexer_peek_token (parser->lexer)->type == CPP_CLOSE_PAREN)
     {
-      if (cxx_dialect < cxx17)
-	pedwarn (input_location, OPT_Wpedantic,
+      if (pedantic && warn_about_dialect_p(cxx17))
+	pedwarn (input_location, OPT_Wc__17_extensions,
 		 "%<static_assert%> without a message "
 		 "only available with %<-std=c++17%> or %<-std=gnu++17%>");
       /* Eat the ')'  */
@@ -20445,8 +20449,8 @@ cp_parser_namespace_definition (cp_parser* parser)
 	  break;
 	}
 
-      if (!nested_definition_count && cxx_dialect < cxx17)
-        pedwarn (input_location, OPT_Wpedantic,
+      if (!nested_definition_count && pedantic && warn_about_dialect_p(cxx17))
+        pedwarn (input_location, OPT_Wc__17_extensions,
 		 "nested namespace definitions only available with "
 		 "%<-std=c++17%> or %<-std=gnu++17%>");
 
@@ -24455,8 +24459,8 @@ cp_parser_initializer_list (cp_parser* parser, bool* non_constant_p,
 	      || (cp_lexer_peek_nth_token (parser->lexer, 3)->type
 		  == CPP_OPEN_BRACE)))
 	{
-	  if (cxx_dialect < cxx20)
-	    pedwarn (loc, OPT_Wpedantic,
+	  if (pedantic && warn_about_dialect_p(cxx20))
+	    pedwarn (loc, OPT_Wc__20_extensions,
 		     "C++ designated initializers only available with "
 		     "%<-std=c++20%> or %<-std=gnu++20%>");
 	  /* Consume the `.'.  */
@@ -26186,9 +26190,9 @@ cp_parser_member_declaration (cp_parser* parser)
 		{
 		  location_t loc
 		    = cp_lexer_peek_token (parser->lexer)->location;
-		  if (cxx_dialect < cxx20
+		  if (warn_about_dialect_p(cxx20)
 		      && identifier != NULL_TREE)
-		    pedwarn (loc, 0,
+		    pedwarn (loc, OPT_Wc__20_extensions,
 			     "default member initializers for bit-fields "
 			     "only available with %<-std=c++20%> or "
 			     "%<-std=gnu++20%>");
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index bf996358328..a2a06066b27 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -2702,8 +2702,8 @@ check_template_variable (tree decl)
   if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)
       && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl)))
     {
-      if (cxx_dialect < cxx14)
-        pedwarn (DECL_SOURCE_LOCATION (decl), 0,
+      if (warn_about_dialect_p(cxx14))
+        pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wc__14_extensions,
 		 "variable templates only available with "
 		 "%<-std=c++14%> or %<-std=gnu++14%>");
 

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 16:32 [PATCH] c++: Add new warning options for C++ language mismatches Jonathan Wakely
@ 2021-05-19 16:39 ` Jonathan Wakely
  2021-05-19 16:46   ` Jonathan Wakely
                     ` (2 more replies)
  2021-05-19 16:40 ` Eric Gallager
  1 sibling, 3 replies; 31+ messages in thread
From: Jonathan Wakely @ 2021-05-19 16:39 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 192 bytes --]

Jakub pointed out I'd forgotten the spaces before the opening parens
for function calls. The attached patch should fix all those, with no
other changes.

Tested x86_64-linux. OK for trunk?




[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 17674 bytes --]

commit a7dc19cdc0c5d3762bb90d12ebd82a05d0013246
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed May 19 17:37:00 2021

    c++: Add new warning options for C++ language mismatches
    
    This adds new warning flags, enabled by default: -Wc++11-extensions,
    -Wc++14-extensions, -Wc++17-extensions, and -Wc++20-extensions. The
    names of the flags are copied from Clang, which already has similar
    options.
    
    No new diagnostics are added, but the new OPT_Wxxx variables are used to
    control existing pedwarns about occurences of new C++ constructs in code
    using an old C++ standard dialect. This allows several existing warnings
    that cannot currently be disabled to be controlled by the appropriate
    -Wno-xxx flag. For example, it will now be possible to disable warnings
    about using variadic templates in C++98 code, by using the new
    -Wno-c++11-extensions option. This will allow libstdc++ headers to
    disable those warnings unconditionally by using diagnostic pragmas, so
    that they are not emitted even if -Wsystem-headers is used.
    
    Some of the affected diagnostics are currently only given when
    -Wpedantic is used. Now that we have a more specific warning flag, we
    could consider making them not depend on -Wpedantic, and only on the new
    flag. This patch does not do that, as it intends to make no changes to
    what is accepted/rejected by default. The only effect should be that
    the new option is shown when -fdiagnostics-show-option is active, and
    that some warnings can be disabled by using the new flags (and for the
    warnings that previously only dependend on -Wpedantic, it will now be
    possible to disable just those warnings while still using -Wpedantic for
    its other benefits).
    
    A new helper function, warn_about_dialect_p, is introduced to avoid the
    repetition of `if (cxx_dialect < cxxNN && warn_cxxNN_extensions)`
    everywhere.
    
    gcc/c-family/ChangeLog:
    
            * c.opt (Wc++11-extensions, Wc++14-extensions)
            (Wc++17-extensions, Wc++20-extensions): New options.
    
    gcc/cp/ChangeLog:
    
            * call.c (maybe_warn_array_conv): Use new function and option.
            * cp-tree.h (warn_about_dialect_p): Declare new function.
            * error.c (maybe_warn_cpp0x): Use new function and options.
            (warn_about_dialect_p): Define new function.
            * parser.c (cp_parser_unqualified_id): Use new function and
            option.
            (cp_parser_pseudo_destructor_name): Likewise.
            (cp_parser_lambda_introducer): Likewise.
            (cp_parser_lambda_declarator_opt): Likewise.
            (cp_parser_init_statement): Likewise.
            (cp_parser_decomposition_declaration): Likewise.
            (cp_parser_function_specifier_opt): Likewise.
            (cp_parser_static_assert): Likewise.
            (cp_parser_namespace_definition): Likewise.
            (cp_parser_initializer_list): Likewise.
            (cp_parser_member_declaration): Likewise.
            * pt.c (check_template_variable): Likewise.

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 5fcf961fd96..a7605cf3a38 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -431,6 +431,22 @@ Wc++20-compat
 C++ ObjC++ Var(warn_cxx20_compat) Warning LangEnabledBy(C++ ObjC++,Wall)
 Warn about C++ constructs whose meaning differs between ISO C++ 2017 and ISO C++ 2020.
 
+Wc++11-extensions
+C++ ObjC++ Var(warn_cxx11_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
+Warn about C++11 constructs in code compiled with an older standard.
+
+Wc++14-extensions
+C++ ObjC++ Var(warn_cxx14_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
+Warn about C++14 constructs in code compiled with an older standard.
+
+Wc++17-extensions
+C++ ObjC++ Var(warn_cxx17_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
+Warn about C++17 constructs in code compiled with an older standard.
+
+Wc++20-extensions
+C++ ObjC++ Var(warn_cxx20_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
+Warn about C++20 constructs in code compiled with an older standard.
+
 Wcast-function-type
 C ObjC C++ ObjC++ Var(warn_cast_function_type) Warning EnabledBy(Wextra)
 Warn about casts between incompatible function types.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 1e2d1d43184..5134d10bb24 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -7464,8 +7464,10 @@ maybe_warn_array_conv (location_t loc, conversion *c, tree expr)
       || TYPE_DOMAIN (type) == NULL_TREE)
     return;
 
-  if (conv_binds_to_array_of_unknown_bound (c))
-    pedwarn (loc, OPT_Wpedantic, "conversions to arrays of unknown bound "
+  if (conv_binds_to_array_of_unknown_bound (c)
+      && pedantic && warn_about_dialect_p (cxx20))
+    pedwarn (loc, OPT_Wc__20_extensions,
+	     "conversions to arrays of unknown bound "
 	     "are only available with %<-std=c++20%> or %<-std=gnu++20%>");
 }
 
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 580db914d40..f0cf5552437 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -6821,6 +6821,7 @@ extern const char *language_to_string		(enum languages);
 extern const char *class_key_or_enum_as_string	(tree);
 extern void maybe_warn_variadic_templates       (void);
 extern void maybe_warn_cpp0x			(cpp0x_warn_str str);
+extern bool warn_about_dialect_p		(enum cxx_dialect);
 extern bool pedwarn_cxx98                       (location_t, int, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4);
 extern location_t location_of                   (tree);
 extern void qualified_name_lookup_error		(tree, tree, tree,
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 3c2276b1976..99689b229b4 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -4403,81 +4403,82 @@ cp_printer (pretty_printer *pp, text_info *text, const char *spec,
 void
 maybe_warn_cpp0x (cpp0x_warn_str str)
 {
-  if (cxx_dialect == cxx98)
+  if (warn_about_dialect_p (cxx11))
     switch (str)
       {
       case CPP0X_INITIALIZER_LISTS:
-	pedwarn (input_location, 0, 
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "extended initializer lists "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_EXPLICIT_CONVERSION:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "explicit conversion operators "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_VARIADIC_TEMPLATES:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "variadic templates "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_LAMBDA_EXPR:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "lambda expressions "
 		  "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_AUTO:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "C++11 auto only available with %<-std=c++11%> or "
 		 "%<-std=gnu++11%>");
 	break;
       case CPP0X_SCOPED_ENUMS:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "scoped enums only available with %<-std=c++11%> or "
 		 "%<-std=gnu++11%>");
 	break;
       case CPP0X_DEFAULTED_DELETED:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "defaulted and deleted functions "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_INLINE_NAMESPACES:
-	pedwarn (input_location, OPT_Wpedantic,
-		 "inline namespaces "
-		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
+	if (pedantic)
+	  pedwarn (input_location, OPT_Wc__11_extensions,
+		   "inline namespaces "
+		   "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_OVERRIDE_CONTROLS:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "override controls (override/final) "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
         break;
       case CPP0X_NSDMI:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "non-static data member initializers "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
         break;
       case CPP0X_USER_DEFINED_LITERALS:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "user-defined literals "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_DELEGATING_CTORS:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "delegating constructors "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
         break;
       case CPP0X_INHERITING_CTORS:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "inheriting constructors "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
         break;
       case CPP0X_ATTRIBUTES:
-	pedwarn (input_location, 0,
-		 "c++11 attributes "
+	pedwarn (input_location, OPT_Wc__11_extensions,
+		 "C++11 attributes "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_REF_QUALIFIER:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "ref-qualifiers "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
@@ -4493,6 +4494,27 @@ maybe_warn_variadic_templates (void)
   maybe_warn_cpp0x (CPP0X_VARIADIC_TEMPLATES);
 }
 
+/* Whether to warn about constructs from C++ standard DIALECT.  */
+bool
+warn_about_dialect_p (enum cxx_dialect dialect)
+{
+  if (cxx_dialect >= dialect)
+    return false;
+
+  switch (dialect)
+    {
+    case cxx11:
+      return warn_cxx11_extensions;
+    case cxx14:
+      return warn_cxx14_extensions;
+    case cxx17:
+      return warn_cxx17_extensions;
+    case cxx20:
+      return warn_cxx20_extensions;
+    default:
+      gcc_unreachable ();
+    }
+}
 
 /* Issue an ISO C++98 pedantic warning at LOCATION, conditional on
    option OPT with text GMSGID.  Use this function to report
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index c0b57955954..3652649c6c6 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -6324,8 +6324,8 @@ cp_parser_unqualified_id (cp_parser* parser,
 	/* ~auto means the destructor of whatever the object is.  */
 	if (cp_parser_is_keyword (token, RID_AUTO))
 	  {
-	    if (cxx_dialect < cxx14)
-	      pedwarn (loc, 0,
+	    if (warn_about_dialect_p (cxx14))
+	      pedwarn (loc, OPT_Wc__14_extensions,
 		       "%<~auto%> only available with "
 		       "%<-std=c++14%> or %<-std=gnu++14%>");
 	    cp_lexer_consume_token (parser->lexer);
@@ -8352,8 +8352,8 @@ cp_parser_pseudo_destructor_name (cp_parser* parser,
       && cp_lexer_nth_token_is_keyword (parser->lexer, 2, RID_AUTO)
       && !type_dependent_expression_p (object))
     {
-      if (cxx_dialect < cxx14)
-	pedwarn (input_location, 0,
+      if (warn_about_dialect_p (cxx14))
+	pedwarn (input_location, OPT_Wc__14_extensions,
 		 "%<~auto%> only available with "
 		 "%<-std=c++14%> or %<-std=gnu++14%>");
       cp_lexer_consume_token (parser->lexer);
@@ -11041,9 +11041,10 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
 	  && cp_lexer_nth_token_is_keyword (parser->lexer, 2, RID_THIS))
 	{
 	  location_t loc = cp_lexer_peek_token (parser->lexer)->location;
-	  if (cxx_dialect < cxx17)
-	    pedwarn (loc, 0, "%<*this%> capture only available with "
-			     "%<-std=c++17%> or %<-std=gnu++17%>");
+	  if (warn_about_dialect_p (cxx17))
+	    pedwarn (loc, OPT_Wc__17_extensions,
+		     "%<*this%> capture only available with "
+		     "%<-std=c++17%> or %<-std=gnu++17%>");
 	  cp_lexer_consume_token (parser->lexer);
 	  cp_lexer_consume_token (parser->lexer);
 	  if (LAMBDA_EXPR_THIS_CAPTURE (lambda_expr))
@@ -11080,8 +11081,9 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
       if (cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS))
 	{
 	  ellipsis_loc = cp_lexer_peek_token (parser->lexer)->location;
-	  if (cxx_dialect < cxx20)
-	    pedwarn (ellipsis_loc, 0, "pack init-capture only available with "
+	  if (warn_about_dialect_p (cxx20))
+	    pedwarn (ellipsis_loc, OPT_Wc__20_extensions,
+		     "pack init-capture only available with "
 		     "%<-std=c++20%> or %<-std=gnu++20%>");
 	  cp_lexer_consume_token (parser->lexer);
 	  init_pack_expansion = true;
@@ -11121,8 +11123,8 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
 	{
 	  bool direct, non_constant;
 	  /* An explicit initializer exists.  */
-	  if (cxx_dialect < cxx14)
-	    pedwarn (input_location, 0,
+	  if (warn_about_dialect_p (cxx14))
+	    pedwarn (input_location, OPT_Wc__14_extensions,
 		     "lambda capture initializers "
 		     "only available with %<-std=c++14%> or %<-std=gnu++14%>");
 	  capture_init_expr = cp_parser_initializer (parser, &direct,
@@ -11295,12 +11297,12 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
      an opening angle if present.  */
   if (cp_lexer_next_token_is (parser->lexer, CPP_LESS))
     {
-      if (cxx_dialect < cxx14)
-	pedwarn (parser->lexer->next_token->location, 0,
+      if (warn_about_dialect_p (cxx14))
+	pedwarn (parser->lexer->next_token->location, OPT_Wc__14_extensions,
 		 "lambda templates are only available with "
 		 "%<-std=c++14%> or %<-std=gnu++14%>");
-      else if (cxx_dialect < cxx20)
-	pedwarn (parser->lexer->next_token->location, OPT_Wpedantic,
+      else if (pedantic && warn_about_dialect_p (cxx20))
+	pedwarn (parser->lexer->next_token->location, OPT_Wc__20_extensions,
 		 "lambda templates are only available with "
 		 "%<-std=c++20%> or %<-std=gnu++20%>");
 
@@ -13421,8 +13423,9 @@ cp_parser_init_statement (cp_parser *parser, tree *decl)
 	  /* It is a range-for, consume the ':'.  */
 	  cp_lexer_consume_token (parser->lexer);
 	  is_range_for = true;
-	  if (cxx_dialect < cxx11)
-	    pedwarn (cp_lexer_peek_token (parser->lexer)->location, 0,
+	  if (warn_about_dialect_p (cxx11))
+	    pedwarn (cp_lexer_peek_token (parser->lexer)->location,
+		     OPT_Wc__11_extensions,
 		     "range-based %<for%> loops only available with "
 		     "%<-std=c++11%> or %<-std=gnu++11%>");
 	}
@@ -14664,9 +14667,10 @@ cp_parser_decomposition_declaration (cp_parser *parser,
 	}
     }
 
-  if (cxx_dialect < cxx17)
-    pedwarn (loc, 0, "structured bindings only available with "
-		     "%<-std=c++17%> or %<-std=gnu++17%>");
+  if (warn_about_dialect_p (cxx17))
+    pedwarn (loc, OPT_Wc__17_extensions,
+	     "structured bindings only available with "
+	     "%<-std=c++17%> or %<-std=gnu++17%>");
 
   tree pushed_scope;
   cp_declarator *declarator = make_declarator (cdk_decomp);
@@ -15260,8 +15264,8 @@ cp_parser_function_specifier_opt (cp_parser* parser,
 	    parser->type_definition_forbidden_message
 	      = G_("types may not be defined in explicit-specifier");
 
-	    if (cxx_dialect < cxx20)
-	      pedwarn (token->location, 0,
+	    if (warn_about_dialect_p (cxx20))
+	      pedwarn (token->location, OPT_Wc__20_extensions,
 		       "%<explicit(bool)%> only available with %<-std=c++20%> "
 		       "or %<-std=gnu++20%>");
 
@@ -15428,8 +15432,8 @@ cp_parser_static_assert(cp_parser *parser, bool member_p)
 
   if (cp_lexer_peek_token (parser->lexer)->type == CPP_CLOSE_PAREN)
     {
-      if (cxx_dialect < cxx17)
-	pedwarn (input_location, OPT_Wpedantic,
+      if (pedantic && warn_about_dialect_p (cxx17))
+	pedwarn (input_location, OPT_Wc__17_extensions,
 		 "%<static_assert%> without a message "
 		 "only available with %<-std=c++17%> or %<-std=gnu++17%>");
       /* Eat the ')'  */
@@ -20445,8 +20449,8 @@ cp_parser_namespace_definition (cp_parser* parser)
 	  break;
 	}
 
-      if (!nested_definition_count && cxx_dialect < cxx17)
-        pedwarn (input_location, OPT_Wpedantic,
+      if (!nested_definition_count && pedantic && warn_about_dialect_p (cxx17))
+        pedwarn (input_location, OPT_Wc__17_extensions,
 		 "nested namespace definitions only available with "
 		 "%<-std=c++17%> or %<-std=gnu++17%>");
 
@@ -24455,8 +24459,8 @@ cp_parser_initializer_list (cp_parser* parser, bool* non_constant_p,
 	      || (cp_lexer_peek_nth_token (parser->lexer, 3)->type
 		  == CPP_OPEN_BRACE)))
 	{
-	  if (cxx_dialect < cxx20)
-	    pedwarn (loc, OPT_Wpedantic,
+	  if (pedantic && warn_about_dialect_p (cxx20))
+	    pedwarn (loc, OPT_Wc__20_extensions,
 		     "C++ designated initializers only available with "
 		     "%<-std=c++20%> or %<-std=gnu++20%>");
 	  /* Consume the `.'.  */
@@ -26186,9 +26190,9 @@ cp_parser_member_declaration (cp_parser* parser)
 		{
 		  location_t loc
 		    = cp_lexer_peek_token (parser->lexer)->location;
-		  if (cxx_dialect < cxx20
+		  if (warn_about_dialect_p (cxx20)
 		      && identifier != NULL_TREE)
-		    pedwarn (loc, 0,
+		    pedwarn (loc, OPT_Wc__20_extensions,
 			     "default member initializers for bit-fields "
 			     "only available with %<-std=c++20%> or "
 			     "%<-std=gnu++20%>");
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index bf996358328..6b7a0419154 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -2702,8 +2702,8 @@ check_template_variable (tree decl)
   if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)
       && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl)))
     {
-      if (cxx_dialect < cxx14)
-        pedwarn (DECL_SOURCE_LOCATION (decl), 0,
+      if (warn_about_dialect_p (cxx14))
+        pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wc__14_extensions,
 		 "variable templates only available with "
 		 "%<-std=c++14%> or %<-std=gnu++14%>");
 

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 16:32 [PATCH] c++: Add new warning options for C++ language mismatches Jonathan Wakely
  2021-05-19 16:39 ` Jonathan Wakely
@ 2021-05-19 16:40 ` Eric Gallager
  2021-05-19 16:50   ` Jonathan Wakely
  1 sibling, 1 reply; 31+ messages in thread
From: Eric Gallager @ 2021-05-19 16:40 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-patches

On Wed, May 19, 2021 at 12:33 PM Jonathan Wakely via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> This adds new warning flags, enabled by default: -Wc++11-extensions,
> -Wc++14-extensions, -Wc++17-extensions, and -Wc++20-extensions. The
> names of the flags are copied from Clang, which already has similar
> options.
>
> No new diagnostics are added, but the new OPT_Wxxx variables are used to
> control existing pedwarns about occurences of new C++ constructs in code
> using an old C++ standard dialect. This allows several existing warnings
> that cannot currently be disabled to be controlled by the appropriate
> -Wno-xxx flag. For example, it will now be possible to disable warnings
> about using variadic templates in C++98 code, by using the new
> -Wno-c++11-extensions option. This will allow libstdc++ headers to
> disable those warnings unconditionally by using diagnostic pragmas, so
> that they are not emitted even if -Wsystem-headers is used.
>
> Some of the affected diagnostics are currently only given when
> -Wpedantic is used. Now that we have a more specific warning flag, we
> could consider making them not depend on -Wpedantic, and only on the new
> flag. This patch does not do that, as it intends to make no changes to
> what is accepted/rejected by default. The only effect should be that
> the new option is shown when -fdiagnostics-show-option is active, and
> that some warnings can be disabled by using the new flags (and for the
> warnings that previously only dependend on -Wpedantic, it will now be
> possible to disable just those warnings while still using -Wpedantic for
> its other benefits).
>
> A new helper function, warn_about_dialect_p, is introduced to avoid the
> repetition of `if (cxx_dialect < cxxNN && warn_cxxNN_extensions)`
> everywhere.
>
> gcc/c-family/ChangeLog:
>
>         * c.opt (Wc++11-extensions, Wc++14-extensions)
>         (Wc++17-extensions, Wc++20-extensions): New options.
>
> gcc/cp/ChangeLog:
>
>         * call.c (maybe_warn_array_conv): Use new function and option.
>         * cp-tree.h (warn_about_dialect_p): Declare new function.
>         * error.c (maybe_warn_cpp0x): Use new function and options.
>         (warn_about_dialect_p): Define new function.
>         * parser.c (cp_parser_unqualified_id): Use new function and
>         option.
>         (cp_parser_pseudo_destructor_name): Likewise.
>         (cp_parser_lambda_introducer): Likewise.
>         (cp_parser_lambda_declarator_opt): Likewise.
>         (cp_parser_init_statement): Likewise.
>         (cp_parser_decomposition_declaration): Likewise.
>         (cp_parser_function_specifier_opt): Likewise.
>         (cp_parser_static_assert): Likewise.
>         (cp_parser_namespace_definition): Likewise.
>         (cp_parser_initializer_list): Likewise.
>         (cp_parser_member_declaration): Likewise.
>         * pt.c (check_template_variable): Likewise.
>
> Tested x86_64-linux. OK for trunk?
>
>

Thank you for doing this! One thing I'm wondering about, is that I'm
pretty sure clang also allows at least some of these to be used with
plain C as well, for example for things like the old use of "auto" in
C conflicting with the newer C++11 meaning of "auto". Would it be
possible to do likewise for GCC as well? Just an idea.
Thanks,
Eric Gallager

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 16:39 ` Jonathan Wakely
@ 2021-05-19 16:46   ` Jonathan Wakely
  2021-05-19 17:26     ` Jason Merrill
  2021-05-19 16:53   ` Marek Polacek
  2021-05-19 17:51   ` [PATCH] c++: Add new warning options for C++ language mismatches Martin Sebor
  2 siblings, 1 reply; 31+ messages in thread
From: Jonathan Wakely @ 2021-05-19 16:46 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 562 bytes --]

On 19/05/21 17:39 +0100, Jonathan Wakely wrote:
>Jakub pointed out I'd forgotten the spaces before the opening parens
>for function calls. The attached patch should fix all those, with no
>other changes.
>
>Tested x86_64-linux. OK for trunk?

Jakub also pointed out we already have some similar diagnostics for
C++23, but I missed them as they say "only optional with" not "only
available with".

I'm testing the incremental change in the attached patch which also
adds -Wc++23-extensions, and I'll resend the full patch after that
finishes.

(Thanks, Jakub!)



[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 2437 bytes --]

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index a7605cf3a38..9fc41d9f2b3 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -447,6 +447,10 @@ Wc++20-extensions
 C++ ObjC++ Var(warn_cxx20_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
 Warn about C++20 constructs in code compiled with an older standard.
 
+Wc++23-extensions
+C++ ObjC++ Var(warn_cxx23_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
+Warn about C++23 constructs in code compiled with an older standard.
+
 Wcast-function-type
 C ObjC C++ ObjC++ Var(warn_cast_function_type) Warning EnabledBy(Wextra)
 Warn about casts between incompatible function types.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 3652649c6c6..ba11a436499 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -11390,7 +11390,7 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
 
   if (omitted_parms_loc && lambda_specs.any_specifiers_p)
     {
-      pedwarn (omitted_parms_loc, 0,
+      pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
 	       "parameter declaration before lambda declaration "
 	       "specifiers only optional with %<-std=c++2b%> or "
 	       "%<-std=gnu++2b%>");
@@ -11409,7 +11409,7 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
   tx_qual = cp_parser_tx_qualifier_opt (parser);
   if (omitted_parms_loc && tx_qual)
     {
-      pedwarn (omitted_parms_loc, 0,
+      pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
 	       "parameter declaration before lambda transaction "
 	       "qualifier only optional with %<-std=c++2b%> or "
 	       "%<-std=gnu++2b%>");
@@ -11422,7 +11422,7 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
 
   if (omitted_parms_loc && exception_spec)
     {
-      pedwarn (omitted_parms_loc, 0,
+      pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
 	       "parameter declaration before lambda exception "
 	       "specification only optional with %<-std=c++2b%> or "
 	       "%<-std=gnu++2b%>");
@@ -11440,7 +11440,7 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
   if (cp_lexer_next_token_is (parser->lexer, CPP_DEREF))
     {
       if (omitted_parms_loc)
-	pedwarn (omitted_parms_loc, 0,
+	pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
 		 "parameter declaration before lambda trailing "
 		 "return type only optional with %<-std=c++2b%> or "
 		 "%<-std=gnu++2b%>");

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 16:40 ` Eric Gallager
@ 2021-05-19 16:50   ` Jonathan Wakely
  2021-05-19 16:56     ` Jonathan Wakely
  0 siblings, 1 reply; 31+ messages in thread
From: Jonathan Wakely @ 2021-05-19 16:50 UTC (permalink / raw)
  To: Eric Gallager; +Cc: gcc-patches

On 19/05/21 12:40 -0400, Eric Gallager wrote:
>Thank you for doing this! One thing I'm wondering about, is that I'm
>pretty sure clang also allows at least some of these to be used with
>plain C as well, for example for things like the old use of "auto" in
>C conflicting with the newer C++11 meaning of "auto". Would it be
>possible to do likewise for GCC as well? Just an idea.

I think that would belong in -Wc++-compat and would need changes to
the C front end, which I'm almost entirely unfamiliar with. My patch
doesn't add any new diagnostics, it just makes slight adjustments to
existing ones. If you want new diagnostics in the C front end you'll
need to convince a C FE maintainer. That would be too far outside my
comfort zone :-)




^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 16:39 ` Jonathan Wakely
  2021-05-19 16:46   ` Jonathan Wakely
@ 2021-05-19 16:53   ` Marek Polacek
  2021-05-19 16:59     ` Jonathan Wakely
  2021-05-19 17:51   ` [PATCH] c++: Add new warning options for C++ language mismatches Martin Sebor
  2 siblings, 1 reply; 31+ messages in thread
From: Marek Polacek @ 2021-05-19 16:53 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-patches

On Wed, May 19, 2021 at 05:39:24PM +0100, Jonathan Wakely via Gcc-patches wrote:
> Jakub pointed out I'd forgotten the spaces before the opening parens
> for function calls. The attached patch should fix all those, with no
> other changes.
> 
> Tested x86_64-linux. OK for trunk?

Nice, this is cool.

> --- a/gcc/c-family/c.opt
> +++ b/gcc/c-family/c.opt
> @@ -431,6 +431,22 @@ Wc++20-compat
>  C++ ObjC++ Var(warn_cxx20_compat) Warning LangEnabledBy(C++ ObjC++,Wall)
>  Warn about C++ constructs whose meaning differs between ISO C++ 2017 and ISO C++ 2020.
>  
> +Wc++11-extensions
> +C++ ObjC++ Var(warn_cxx11_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
> +Warn about C++11 constructs in code compiled with an older standard.
> +
> +Wc++14-extensions
> +C++ ObjC++ Var(warn_cxx14_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
> +Warn about C++14 constructs in code compiled with an older standard.
> +
> +Wc++17-extensions
> +C++ ObjC++ Var(warn_cxx17_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
> +Warn about C++17 constructs in code compiled with an older standard.
> +
> +Wc++20-extensions
> +C++ ObjC++ Var(warn_cxx20_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
> +Warn about C++20 constructs in code compiled with an older standard.
> +

So these are enabled by -Wall but also turned on by default?  Let's choose one
and then drop either the Init(1) or the LangEnabledBy(C++ ObjC++,Wall) part?

Marek


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 16:50   ` Jonathan Wakely
@ 2021-05-19 16:56     ` Jonathan Wakely
  0 siblings, 0 replies; 31+ messages in thread
From: Jonathan Wakely @ 2021-05-19 16:56 UTC (permalink / raw)
  To: Eric Gallager; +Cc: gcc-patches

On 19/05/21 17:50 +0100, Jonathan Wakely wrote:
>On 19/05/21 12:40 -0400, Eric Gallager wrote:
>>Thank you for doing this! One thing I'm wondering about, is that I'm
>>pretty sure clang also allows at least some of these to be used with
>>plain C as well, for example for things like the old use of "auto" in
>>C conflicting with the newer C++11 meaning of "auto". Would it be
>>possible to do likewise for GCC as well? Just an idea.
>
>I think that would belong in -Wc++-compat and would need changes to
>the C front end, which I'm almost entirely unfamiliar with. My patch
>doesn't add any new diagnostics, it just makes slight adjustments to
>existing ones. If you want new diagnostics in the C front end you'll
>need to convince a C FE maintainer. That would be too far outside my
>comfort zone :-)

FWIW, Clang does accept -Wc++11-extensions as an option for the C
compiler, but I think that's true for all its warning options (I don't
think it ever rejects a warning option as "valid for C++ but not for
C" the way that GCC does). But I can't persuade it to warn about using
'auto' in C, even with -Weverything.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 16:53   ` Marek Polacek
@ 2021-05-19 16:59     ` Jonathan Wakely
  2021-05-19 17:09       ` Marek Polacek
  0 siblings, 1 reply; 31+ messages in thread
From: Jonathan Wakely @ 2021-05-19 16:59 UTC (permalink / raw)
  To: Marek Polacek; +Cc: gcc-patches

On 19/05/21 12:53 -0400, Marek Polacek wrote:
>On Wed, May 19, 2021 at 05:39:24PM +0100, Jonathan Wakely via Gcc-patches wrote:
>> Jakub pointed out I'd forgotten the spaces before the opening parens
>> for function calls. The attached patch should fix all those, with no
>> other changes.
>>
>> Tested x86_64-linux. OK for trunk?
>
>Nice, this is cool.
>
>> --- a/gcc/c-family/c.opt
>> +++ b/gcc/c-family/c.opt
>> @@ -431,6 +431,22 @@ Wc++20-compat
>>  C++ ObjC++ Var(warn_cxx20_compat) Warning LangEnabledBy(C++ ObjC++,Wall)
>>  Warn about C++ constructs whose meaning differs between ISO C++ 2017 and ISO C++ 2020.
>>
>> +Wc++11-extensions
>> +C++ ObjC++ Var(warn_cxx11_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
>> +Warn about C++11 constructs in code compiled with an older standard.
>> +
>> +Wc++14-extensions
>> +C++ ObjC++ Var(warn_cxx14_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
>> +Warn about C++14 constructs in code compiled with an older standard.
>> +
>> +Wc++17-extensions
>> +C++ ObjC++ Var(warn_cxx17_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
>> +Warn about C++17 constructs in code compiled with an older standard.
>> +
>> +Wc++20-extensions
>> +C++ ObjC++ Var(warn_cxx20_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
>> +Warn about C++20 constructs in code compiled with an older standard.
>> +
>
>So these are enabled by -Wall but also turned on by default?  Let's choose one
>and then drop either the Init(1) or the LangEnabledBy(C++ ObjC++,Wall) part?

Ah, good point. I mostly just cargo-cult what I see in that file (is
the format documented somewhere?)

I think to preserve the current behaviour (using these constructs in
an unsupported dialect warns by default) we want them to be Init(1)
but not in -Wall. Or we could change the behaviour, and include them
in -Wall and not Init(1), but then people who don't use -Wall (aka
idiots and beginners) would not get the warnings.

Any preference?


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 16:59     ` Jonathan Wakely
@ 2021-05-19 17:09       ` Marek Polacek
  2022-03-29  9:27         ` options, '-Wc++[...]-extensions': Remove undefined one-argument 'LangEnabledBy' option properties (was: [PATCH] c++: Add new warning options for C++ language mismatches) Thomas Schwinge
  0 siblings, 1 reply; 31+ messages in thread
From: Marek Polacek @ 2021-05-19 17:09 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-patches

On Wed, May 19, 2021 at 05:59:34PM +0100, Jonathan Wakely wrote:
> On 19/05/21 12:53 -0400, Marek Polacek wrote:
> > On Wed, May 19, 2021 at 05:39:24PM +0100, Jonathan Wakely via Gcc-patches wrote:
> > > Jakub pointed out I'd forgotten the spaces before the opening parens
> > > for function calls. The attached patch should fix all those, with no
> > > other changes.
> > > 
> > > Tested x86_64-linux. OK for trunk?
> > 
> > Nice, this is cool.
> > 
> > > --- a/gcc/c-family/c.opt
> > > +++ b/gcc/c-family/c.opt
> > > @@ -431,6 +431,22 @@ Wc++20-compat
> > >  C++ ObjC++ Var(warn_cxx20_compat) Warning LangEnabledBy(C++ ObjC++,Wall)
> > >  Warn about C++ constructs whose meaning differs between ISO C++ 2017 and ISO C++ 2020.
> > > 
> > > +Wc++11-extensions
> > > +C++ ObjC++ Var(warn_cxx11_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
> > > +Warn about C++11 constructs in code compiled with an older standard.
> > > +
> > > +Wc++14-extensions
> > > +C++ ObjC++ Var(warn_cxx14_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
> > > +Warn about C++14 constructs in code compiled with an older standard.
> > > +
> > > +Wc++17-extensions
> > > +C++ ObjC++ Var(warn_cxx17_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
> > > +Warn about C++17 constructs in code compiled with an older standard.
> > > +
> > > +Wc++20-extensions
> > > +C++ ObjC++ Var(warn_cxx20_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
> > > +Warn about C++20 constructs in code compiled with an older standard.
> > > +
> > 
> > So these are enabled by -Wall but also turned on by default?  Let's choose one
> > and then drop either the Init(1) or the LangEnabledBy(C++ ObjC++,Wall) part?
> 
> Ah, good point. I mostly just cargo-cult what I see in that file (is
> the format documented somewhere?)

doc/options.texi I think.
 
> I think to preserve the current behaviour (using these constructs in
> an unsupported dialect warns by default) we want them to be Init(1)
> but not in -Wall. Or we could change the behaviour, and include them
> in -Wall and not Init(1), but then people who don't use -Wall (aka
> idiots and beginners) would not get the warnings.
> 
> Any preference?

Um.  Probably Init(1) aka status quo.  Frankly it sounds like a -pedantic thing
to me, but I guess let's not change that now.

Marek


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 16:46   ` Jonathan Wakely
@ 2021-05-19 17:26     ` Jason Merrill
  2021-05-19 19:55       ` Jonathan Wakely
  0 siblings, 1 reply; 31+ messages in thread
From: Jason Merrill @ 2021-05-19 17:26 UTC (permalink / raw)
  To: Jonathan Wakely, gcc-patches

On 5/19/21 12:46 PM, Jonathan Wakely wrote:
> On 19/05/21 17:39 +0100, Jonathan Wakely wrote:
>> Jakub pointed out I'd forgotten the spaces before the opening parens
>> for function calls. The attached patch should fix all those, with no
>> other changes.
>>
>> Tested x86_64-linux. OK for trunk?
> 
> Jakub also pointed out we already have some similar diagnostics for
> C++23, but I missed them as they say "only optional with" not "only
> available with".
> 
> I'm testing the incremental change in the attached patch which also
> adds -Wc++23-extensions, and I'll resend the full patch after that
> finishes.

>    if (omitted_parms_loc && lambda_specs.any_specifiers_p)
>      {
> -      pedwarn (omitted_parms_loc, 0,
> +      pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,

You probably want to change

>   else if (cxx_dialect < cxx23)
>     omitted_parms_loc = cp_lexer_peek_token (parser->lexer)->location;

To use warn_about_dialect_p.

Jason


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 16:39 ` Jonathan Wakely
  2021-05-19 16:46   ` Jonathan Wakely
  2021-05-19 16:53   ` Marek Polacek
@ 2021-05-19 17:51   ` Martin Sebor
  2021-05-19 18:03     ` Marek Polacek
                       ` (2 more replies)
  2 siblings, 3 replies; 31+ messages in thread
From: Martin Sebor @ 2021-05-19 17:51 UTC (permalink / raw)
  To: Jonathan Wakely, gcc-patches

On 5/19/21 10:39 AM, Jonathan Wakely via Gcc-patches wrote:
> Jakub pointed out I'd forgotten the spaces before the opening parens
> for function calls. The attached patch should fix all those, with no
> other changes.
> 
> Tested x86_64-linux. OK for trunk?

Looks good to me, it just needs an update to the manual describing
the new options.

It's too bad that the conditionals checking for the dialect have
to be repeated throughout the front end.  They're implied by
the new option enumerator passed to pedwarn().  If the diagnostic
subsystem had access to cxx_dialect the check could be done there
and all the other conditionals could be avoided.  An alternative
to that would be to add a new wrapper to the C++ front end, like
cxxdialect_pedwarn, to do the checking before calling pedwarn
(or, more likely, emit_diagnostic_valist).

Martin

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 17:51   ` [PATCH] c++: Add new warning options for C++ language mismatches Martin Sebor
@ 2021-05-19 18:03     ` Marek Polacek
  2021-05-19 18:35       ` Jonathan Wakely
  2021-05-19 23:05     ` Jonathan Wakely
  2021-05-19 23:12     ` Jonathan Wakely
  2 siblings, 1 reply; 31+ messages in thread
From: Marek Polacek @ 2021-05-19 18:03 UTC (permalink / raw)
  To: Martin Sebor; +Cc: Jonathan Wakely, gcc-patches

On Wed, May 19, 2021 at 11:51:54AM -0600, Martin Sebor via Gcc-patches wrote:
> On 5/19/21 10:39 AM, Jonathan Wakely via Gcc-patches wrote:
> > Jakub pointed out I'd forgotten the spaces before the opening parens
> > for function calls. The attached patch should fix all those, with no
> > other changes.
> > 
> > Tested x86_64-linux. OK for trunk?
> 
> Looks good to me, it just needs an update to the manual describing
> the new options.
> 
> It's too bad that the conditionals checking for the dialect have
> to be repeated throughout the front end.  They're implied by
> the new option enumerator passed to pedwarn().  If the diagnostic
> subsystem had access to cxx_dialect the check could be done there
> and all the other conditionals could be avoided.  An alternative
> to that would be to add a new wrapper to the C++ front end, like
> cxxdialect_pedwarn, to do the checking before calling pedwarn
> (or, more likely, emit_diagnostic_valist).

In the C FE I introduced pedwarn_c11 and similar to deal with a similar
problem, and also handle the rule that a more specific warning overrides
more general warnings.

Marek


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 18:03     ` Marek Polacek
@ 2021-05-19 18:35       ` Jonathan Wakely
  2021-05-19 18:41         ` Marek Polacek
  0 siblings, 1 reply; 31+ messages in thread
From: Jonathan Wakely @ 2021-05-19 18:35 UTC (permalink / raw)
  To: Marek Polacek; +Cc: Martin Sebor, gcc-patches

On 19/05/21 14:03 -0400, Marek Polacek wrote:
>On Wed, May 19, 2021 at 11:51:54AM -0600, Martin Sebor via Gcc-patches wrote:
>> On 5/19/21 10:39 AM, Jonathan Wakely via Gcc-patches wrote:
>> > Jakub pointed out I'd forgotten the spaces before the opening parens
>> > for function calls. The attached patch should fix all those, with no
>> > other changes.
>> >
>> > Tested x86_64-linux. OK for trunk?
>>
>> Looks good to me, it just needs an update to the manual describing
>> the new options.
>>
>> It's too bad that the conditionals checking for the dialect have
>> to be repeated throughout the front end.  They're implied by
>> the new option enumerator passed to pedwarn().  If the diagnostic
>> subsystem had access to cxx_dialect the check could be done there
>> and all the other conditionals could be avoided.  An alternative
>> to that would be to add a new wrapper to the C++ front end, like
>> cxxdialect_pedwarn, to do the checking before calling pedwarn
>> (or, more likely, emit_diagnostic_valist).
>
>In the C FE I introduced pedwarn_c11 and similar to deal with a similar
>problem, and also handle the rule that a more specific warning overrides
>more general warnings.

The C++ FE does already have pedwarn_cxx98, but generalizing that
would have taken more effort than I wanted to spend on this, sorry :-(



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 18:35       ` Jonathan Wakely
@ 2021-05-19 18:41         ` Marek Polacek
  0 siblings, 0 replies; 31+ messages in thread
From: Marek Polacek @ 2021-05-19 18:41 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: Martin Sebor, gcc-patches

On Wed, May 19, 2021 at 07:35:20PM +0100, Jonathan Wakely wrote:
> On 19/05/21 14:03 -0400, Marek Polacek wrote:
> > On Wed, May 19, 2021 at 11:51:54AM -0600, Martin Sebor via Gcc-patches wrote:
> > > On 5/19/21 10:39 AM, Jonathan Wakely via Gcc-patches wrote:
> > > > Jakub pointed out I'd forgotten the spaces before the opening parens
> > > > for function calls. The attached patch should fix all those, with no
> > > > other changes.
> > > >
> > > > Tested x86_64-linux. OK for trunk?
> > > 
> > > Looks good to me, it just needs an update to the manual describing
> > > the new options.
> > > 
> > > It's too bad that the conditionals checking for the dialect have
> > > to be repeated throughout the front end.  They're implied by
> > > the new option enumerator passed to pedwarn().  If the diagnostic
> > > subsystem had access to cxx_dialect the check could be done there
> > > and all the other conditionals could be avoided.  An alternative
> > > to that would be to add a new wrapper to the C++ front end, like
> > > cxxdialect_pedwarn, to do the checking before calling pedwarn
> > > (or, more likely, emit_diagnostic_valist).
> > 
> > In the C FE I introduced pedwarn_c11 and similar to deal with a similar
> > problem, and also handle the rule that a more specific warning overrides
> > more general warnings.
> 
> The C++ FE does already have pedwarn_cxx98, but generalizing that
> would have taken more effort than I wanted to spend on this, sorry :-(

No worries, that's understandable.  I think the patch is a good improvement
as-is.  (Though some doc text into the doc/invoke.texi should be added.)

Marek


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 17:26     ` Jason Merrill
@ 2021-05-19 19:55       ` Jonathan Wakely
  2021-05-19 20:05         ` Jonathan Wakely
  2021-05-19 20:05         ` Jason Merrill
  0 siblings, 2 replies; 31+ messages in thread
From: Jonathan Wakely @ 2021-05-19 19:55 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

On 19/05/21 13:26 -0400, Jason Merrill wrote:
>On 5/19/21 12:46 PM, Jonathan Wakely wrote:
>>On 19/05/21 17:39 +0100, Jonathan Wakely wrote:
>>>Jakub pointed out I'd forgotten the spaces before the opening parens
>>>for function calls. The attached patch should fix all those, with no
>>>other changes.
>>>
>>>Tested x86_64-linux. OK for trunk?
>>
>>Jakub also pointed out we already have some similar diagnostics for
>>C++23, but I missed them as they say "only optional with" not "only
>>available with".
>>
>>I'm testing the incremental change in the attached patch which also
>>adds -Wc++23-extensions, and I'll resend the full patch after that
>>finishes.
>
>>   if (omitted_parms_loc && lambda_specs.any_specifiers_p)
>>     {
>>-      pedwarn (omitted_parms_loc, 0,
>>+      pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
>
>You probably want to change
>
>>  else if (cxx_dialect < cxx23)
>>    omitted_parms_loc = cp_lexer_peek_token (parser->lexer)->location;
>
>To use warn_about_dialect_p.

Ah yes.

And just above that there's another pedwarn about a C++14 feature
being used:


       /* Default arguments shall not be specified in the
	 parameter-declaration-clause of a lambda-declarator.  */
       if (cxx_dialect < cxx14)
	for (tree t = param_list; t; t = TREE_CHAIN (t))
	  if (TREE_PURPOSE (t) && DECL_P (TREE_VALUE (t)))
	    pedwarn (DECL_SOURCE_LOCATION (TREE_VALUE (t)), OPT_Wpedantic,
		     "default argument specified for lambda parameter");


I didn't notice that one initially. That should also use
warn_about_dialect_p and OPT_Wc__14_extensions.

Should I change the message to say "init capture" rather than
"default argument"?

I'll add some docs to invoke.texi and get a new patch out.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 19:55       ` Jonathan Wakely
@ 2021-05-19 20:05         ` Jonathan Wakely
  2021-05-19 20:08           ` Jason Merrill
  2021-05-19 20:05         ` Jason Merrill
  1 sibling, 1 reply; 31+ messages in thread
From: Jonathan Wakely @ 2021-05-19 20:05 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

On 19/05/21 20:55 +0100, Jonathan Wakely wrote:
>On 19/05/21 13:26 -0400, Jason Merrill wrote:
>>On 5/19/21 12:46 PM, Jonathan Wakely wrote:
>>>On 19/05/21 17:39 +0100, Jonathan Wakely wrote:
>>>>Jakub pointed out I'd forgotten the spaces before the opening parens
>>>>for function calls. The attached patch should fix all those, with no
>>>>other changes.
>>>>
>>>>Tested x86_64-linux. OK for trunk?
>>>
>>>Jakub also pointed out we already have some similar diagnostics for
>>>C++23, but I missed them as they say "only optional with" not "only
>>>available with".
>>>
>>>I'm testing the incremental change in the attached patch which also
>>>adds -Wc++23-extensions, and I'll resend the full patch after that
>>>finishes.
>>
>>>  if (omitted_parms_loc && lambda_specs.any_specifiers_p)
>>>    {
>>>-      pedwarn (omitted_parms_loc, 0,
>>>+      pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
>>
>>You probably want to change
>>
>>> else if (cxx_dialect < cxx23)
>>>   omitted_parms_loc = cp_lexer_peek_token (parser->lexer)->location;
>>
>>To use warn_about_dialect_p.
>
>Ah yes.
>
>And just above that there's another pedwarn about a C++14 feature
>being used:
>
>
>      /* Default arguments shall not be specified in the
>	 parameter-declaration-clause of a lambda-declarator.  */
>      if (cxx_dialect < cxx14)
>	for (tree t = param_list; t; t = TREE_CHAIN (t))
>	  if (TREE_PURPOSE (t) && DECL_P (TREE_VALUE (t)))
>	    pedwarn (DECL_SOURCE_LOCATION (TREE_VALUE (t)), OPT_Wpedantic,
>		     "default argument specified for lambda parameter");
>
>
>I didn't notice that one initially. That should also use
>warn_about_dialect_p and OPT_Wc__14_extensions.
>
>Should I change the message to say "init capture" rather than
>"default argument"?
>
>I'll add some docs to invoke.texi and get a new patch out.

Oh, also we have https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93769
which points out a problem with the current wording. Not a very
important one, but still ...

While I'm touching all 38(?) places that say "only available with
-std=c++NN or -std=gnu++NN I could change them to say something like
"only available since C++NN". Should I bother?

Clang's equivalent warnings say "are a C++11 feature" e.g.

ext.C:1:17: warning: inline namespaces are a C++11 feature [-Wc++11-inline-namespace]

(They have a specific warning for each feature, with
-Wc++11-extensions to control them all at once.)



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 19:55       ` Jonathan Wakely
  2021-05-19 20:05         ` Jonathan Wakely
@ 2021-05-19 20:05         ` Jason Merrill
  2021-05-20 12:56           ` Jonathan Wakely
  1 sibling, 1 reply; 31+ messages in thread
From: Jason Merrill @ 2021-05-19 20:05 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-patches

On 5/19/21 3:55 PM, Jonathan Wakely wrote:
> On 19/05/21 13:26 -0400, Jason Merrill wrote:
>> On 5/19/21 12:46 PM, Jonathan Wakely wrote:
>>> On 19/05/21 17:39 +0100, Jonathan Wakely wrote:
>>>> Jakub pointed out I'd forgotten the spaces before the opening parens
>>>> for function calls. The attached patch should fix all those, with no
>>>> other changes.
>>>>
>>>> Tested x86_64-linux. OK for trunk?
>>>
>>> Jakub also pointed out we already have some similar diagnostics for
>>> C++23, but I missed them as they say "only optional with" not "only
>>> available with".
>>>
>>> I'm testing the incremental change in the attached patch which also
>>> adds -Wc++23-extensions, and I'll resend the full patch after that
>>> finishes.
>>
>>>   if (omitted_parms_loc && lambda_specs.any_specifiers_p)
>>>     {
>>> -      pedwarn (omitted_parms_loc, 0,
>>> +      pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
>>
>> You probably want to change
>>
>>>  else if (cxx_dialect < cxx23)
>>>    omitted_parms_loc = cp_lexer_peek_token (parser->lexer)->location;
>>
>> To use warn_about_dialect_p.
> 
> Ah yes.
> 
> And just above that there's another pedwarn about a C++14 feature
> being used:
> 
> 
>       /* Default arguments shall not be specified in the
>       parameter-declaration-clause of a lambda-declarator.  */
>       if (cxx_dialect < cxx14)
>      for (tree t = param_list; t; t = TREE_CHAIN (t))
>        if (TREE_PURPOSE (t) && DECL_P (TREE_VALUE (t)))
>          pedwarn (DECL_SOURCE_LOCATION (TREE_VALUE (t)), OPT_Wpedantic,
>               "default argument specified for lambda parameter");
> 
> 
> I didn't notice that one initially. That should also use
> warn_about_dialect_p and OPT_Wc__14_extensions.

Indeed.

> Should I change the message to say "init capture" rather than
> "default argument"?

No, this is about e.g. [](int = 42){}

Jason


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 20:05         ` Jonathan Wakely
@ 2021-05-19 20:08           ` Jason Merrill
  2021-05-19 22:52             ` Jonathan Wakely
  0 siblings, 1 reply; 31+ messages in thread
From: Jason Merrill @ 2021-05-19 20:08 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-patches

On 5/19/21 4:05 PM, Jonathan Wakely wrote:
> On 19/05/21 20:55 +0100, Jonathan Wakely wrote:
>> On 19/05/21 13:26 -0400, Jason Merrill wrote:
>>> On 5/19/21 12:46 PM, Jonathan Wakely wrote:
>>>> On 19/05/21 17:39 +0100, Jonathan Wakely wrote:
>>>>> Jakub pointed out I'd forgotten the spaces before the opening parens
>>>>> for function calls. The attached patch should fix all those, with no
>>>>> other changes.
>>>>>
>>>>> Tested x86_64-linux. OK for trunk?
>>>>
>>>> Jakub also pointed out we already have some similar diagnostics for
>>>> C++23, but I missed them as they say "only optional with" not "only
>>>> available with".
>>>>
>>>> I'm testing the incremental change in the attached patch which also
>>>> adds -Wc++23-extensions, and I'll resend the full patch after that
>>>> finishes.
>>>
>>>>  if (omitted_parms_loc && lambda_specs.any_specifiers_p)
>>>>    {
>>>> -      pedwarn (omitted_parms_loc, 0,
>>>> +      pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
>>>
>>> You probably want to change
>>>
>>>> else if (cxx_dialect < cxx23)
>>>>   omitted_parms_loc = cp_lexer_peek_token (parser->lexer)->location;
>>>
>>> To use warn_about_dialect_p.
>>
>> Ah yes.
>>
>> And just above that there's another pedwarn about a C++14 feature
>> being used:
>>
>>
>>      /* Default arguments shall not be specified in the
>>      parameter-declaration-clause of a lambda-declarator.  */
>>      if (cxx_dialect < cxx14)
>>     for (tree t = param_list; t; t = TREE_CHAIN (t))
>>       if (TREE_PURPOSE (t) && DECL_P (TREE_VALUE (t)))
>>         pedwarn (DECL_SOURCE_LOCATION (TREE_VALUE (t)), OPT_Wpedantic,
>>              "default argument specified for lambda parameter");
>>
>>
>> I didn't notice that one initially. That should also use
>> warn_about_dialect_p and OPT_Wc__14_extensions.
>>
>> Should I change the message to say "init capture" rather than
>> "default argument"?
>>
>> I'll add some docs to invoke.texi and get a new patch out.
> 
> Oh, also we have https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93769
> which points out a problem with the current wording. Not a very
> important one, but still ...
> 
> While I'm touching all 38(?) places that say "only available with
> -std=c++NN or -std=gnu++NN I could change them to say something like
> "only available since C++NN". Should I bother?
> 
> Clang's equivalent warnings say "are a C++11 feature" e.g.
> 
> ext.C:1:17: warning: inline namespaces are a C++11 feature 
> [-Wc++11-inline-namespace]
> 
> (They have a specific warning for each feature, with
> -Wc++11-extensions to control them all at once.)

The clang wording seems more accurate, as that PR points out.

Jason


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 20:08           ` Jason Merrill
@ 2021-05-19 22:52             ` Jonathan Wakely
  2021-05-20 20:05               ` Jonathan Wakely
  0 siblings, 1 reply; 31+ messages in thread
From: Jonathan Wakely @ 2021-05-19 22:52 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

On 19/05/21 16:08 -0400, Jason Merrill wrote:
>On 5/19/21 4:05 PM, Jonathan Wakely wrote:
>>On 19/05/21 20:55 +0100, Jonathan Wakely wrote:
>>>On 19/05/21 13:26 -0400, Jason Merrill wrote:
>>>>On 5/19/21 12:46 PM, Jonathan Wakely wrote:
>>>>>On 19/05/21 17:39 +0100, Jonathan Wakely wrote:
>>>>>>Jakub pointed out I'd forgotten the spaces before the opening parens
>>>>>>for function calls. The attached patch should fix all those, with no
>>>>>>other changes.
>>>>>>
>>>>>>Tested x86_64-linux. OK for trunk?
>>>>>
>>>>>Jakub also pointed out we already have some similar diagnostics for
>>>>>C++23, but I missed them as they say "only optional with" not "only
>>>>>available with".
>>>>>
>>>>>I'm testing the incremental change in the attached patch which also
>>>>>adds -Wc++23-extensions, and I'll resend the full patch after that
>>>>>finishes.
>>>>
>>>>> if (omitted_parms_loc && lambda_specs.any_specifiers_p)
>>>>>   {
>>>>>-      pedwarn (omitted_parms_loc, 0,
>>>>>+      pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
>>>>
>>>>You probably want to change
>>>>
>>>>>else if (cxx_dialect < cxx23)
>>>>>  omitted_parms_loc = cp_lexer_peek_token (parser->lexer)->location;
>>>>
>>>>To use warn_about_dialect_p.
>>>
>>>Ah yes.
>>>
>>>And just above that there's another pedwarn about a C++14 feature
>>>being used:
>>>
>>>
>>>     /* Default arguments shall not be specified in the
>>>     parameter-declaration-clause of a lambda-declarator.  */
>>>     if (cxx_dialect < cxx14)
>>>    for (tree t = param_list; t; t = TREE_CHAIN (t))
>>>      if (TREE_PURPOSE (t) && DECL_P (TREE_VALUE (t)))
>>>        pedwarn (DECL_SOURCE_LOCATION (TREE_VALUE (t)), OPT_Wpedantic,
>>>             "default argument specified for lambda parameter");
>>>
>>>
>>>I didn't notice that one initially. That should also use
>>>warn_about_dialect_p and OPT_Wc__14_extensions.
>>>
>>>Should I change the message to say "init capture" rather than
>>>"default argument"?
>>>
>>>I'll add some docs to invoke.texi and get a new patch out.
>>
>>Oh, also we have https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93769
>>which points out a problem with the current wording. Not a very
>>important one, but still ...
>>
>>While I'm touching all 38(?) places that say "only available with
>>-std=c++NN or -std=gnu++NN I could change them to say something like
>>"only available since C++NN". Should I bother?
>>
>>Clang's equivalent warnings say "are a C++11 feature" e.g.
>>
>>ext.C:1:17: warning: inline namespaces are a C++11 feature 
>>[-Wc++11-inline-namespace]
>>
>>(They have a specific warning for each feature, with
>>-Wc++11-extensions to control them all at once.)
>
>The clang wording seems more accurate, as that PR points out.

OK, that requires touching a number of error_at and inform calls as
well as the pedwarns, so I'll address that separately in a later
patch.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 17:51   ` [PATCH] c++: Add new warning options for C++ language mismatches Martin Sebor
  2021-05-19 18:03     ` Marek Polacek
@ 2021-05-19 23:05     ` Jonathan Wakely
  2021-05-19 23:12     ` Jonathan Wakely
  2 siblings, 0 replies; 31+ messages in thread
From: Jonathan Wakely @ 2021-05-19 23:05 UTC (permalink / raw)
  To: Martin Sebor; +Cc: gcc-patches

On 19/05/21 11:51 -0600, Martin Sebor wrote:
>On 5/19/21 10:39 AM, Jonathan Wakely via Gcc-patches wrote:
>>Jakub pointed out I'd forgotten the spaces before the opening parens
>>for function calls. The attached patch should fix all those, with no
>>other changes.
>>
>>Tested x86_64-linux. OK for trunk?
>
>Looks good to me, it just needs an update to the manual describing
>the new options.
>
>It's too bad that the conditionals checking for the dialect have
>to be repeated throughout the front end.  They're implied by
>the new option enumerator passed to pedwarn().  If the diagnostic
>subsystem had access to cxx_dialect the check could be done there
>and all the other conditionals could be avoided.  An alternative
>to that would be to add a new wrapper to the C++ front end, like
>cxxdialect_pedwarn, to do the checking before calling pedwarn
>(or, more likely, emit_diagnostic_valist).

Actually, you've made me realise the conditionals aren't really
needed. The new warn_about_dialect_p predicate made sense for an
earlier version of my patch, but then I simplified it and now it's
mostly useless.

So in most places I can just leave if (cxx_dialect < cxx17) as the
controlling condition, and then just use OPT_Wc__17_extensions for the
pedwarn opt_code. And even the cxx_dialect check could be eliminated
if the value of warn_cxx11_extensions was set according to the
cxx_dialect (instead of Init(1) for all of them). i.e. Use Init(-1)
and then during option parsing set each according to the -std option:

   if (warn_cxx11_extensions == -1)
     warn_cxx11_extensions = cxx_dialect < cxx11;
   if (warn_cxx14_extensions == -1)
     warn_cxx14_extensions = cxx_dialect < cxx14;
   if (warn_cxx17_extensions == -1)
     warn_cxx17_extensions = cxx_dialect < cxx17;
   etc.

IIUC that would mean that a pedwarn using OPT_Wc__14_extensions will
not warn when cxx_dialect >= cxx14, i.e. only warn about C++14
extensions if the active -std dialect is older than C++14. Which would
mean checking cxx_dialect before the pedwarn isn't needed.




^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 17:51   ` [PATCH] c++: Add new warning options for C++ language mismatches Martin Sebor
  2021-05-19 18:03     ` Marek Polacek
  2021-05-19 23:05     ` Jonathan Wakely
@ 2021-05-19 23:12     ` Jonathan Wakely
  2 siblings, 0 replies; 31+ messages in thread
From: Jonathan Wakely @ 2021-05-19 23:12 UTC (permalink / raw)
  To: Martin Sebor; +Cc: gcc-patches

On 19/05/21 11:51 -0600, Martin Sebor wrote:
>On 5/19/21 10:39 AM, Jonathan Wakely via Gcc-patches wrote:
>>Jakub pointed out I'd forgotten the spaces before the opening parens
>>for function calls. The attached patch should fix all those, with no
>>other changes.
>>
>>Tested x86_64-linux. OK for trunk?
>
>Looks good to me, it just needs an update to the manual describing
>the new options.
>
>It's too bad that the conditionals checking for the dialect have
>to be repeated throughout the front end.  They're implied by
>the new option enumerator passed to pedwarn().  If the diagnostic
>subsystem had access to cxx_dialect the check could be done there
>and all the other conditionals could be avoided.  An alternative
>to that would be to add a new wrapper to the C++ front end, like
>cxxdialect_pedwarn, to do the checking before calling pedwarn
>(or, more likely, emit_diagnostic_valist).

btw I did try adding that new wrapper, but it got complicated when I
needed to overload it for both location_t and richloc* (and also
overload all the forwarding wrappers for each cxx dialect that used
it). I gave up and reverted everything.

Maybe I'll try that again another day, but for now I just need to be
able to disable some of these warnings with -Wno-xxx, because they're
not currently controllable by any option.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 20:05         ` Jason Merrill
@ 2021-05-20 12:56           ` Jonathan Wakely
  2021-05-20 16:34             ` Jason Merrill
  2021-05-20 17:25             ` Martin Sebor
  0 siblings, 2 replies; 31+ messages in thread
From: Jonathan Wakely @ 2021-05-20 12:56 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches, Marek Polacek, Martin Sebor

[-- Attachment #1: Type: text/plain, Size: 2249 bytes --]

On 19/05/21 16:05 -0400, Jason Merrill wrote:
>On 5/19/21 3:55 PM, Jonathan Wakely wrote:
>>On 19/05/21 13:26 -0400, Jason Merrill wrote:
>>>On 5/19/21 12:46 PM, Jonathan Wakely wrote:
>>>>On 19/05/21 17:39 +0100, Jonathan Wakely wrote:
>>>>>Jakub pointed out I'd forgotten the spaces before the opening parens
>>>>>for function calls. The attached patch should fix all those, with no
>>>>>other changes.
>>>>>
>>>>>Tested x86_64-linux. OK for trunk?
>>>>
>>>>Jakub also pointed out we already have some similar diagnostics for
>>>>C++23, but I missed them as they say "only optional with" not "only
>>>>available with".
>>>>
>>>>I'm testing the incremental change in the attached patch which also
>>>>adds -Wc++23-extensions, and I'll resend the full patch after that
>>>>finishes.
>>>
>>>>  if (omitted_parms_loc && lambda_specs.any_specifiers_p)
>>>>    {
>>>>-      pedwarn (omitted_parms_loc, 0,
>>>>+      pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
>>>
>>>You probably want to change
>>>
>>>> else if (cxx_dialect < cxx23)
>>>>   omitted_parms_loc = cp_lexer_peek_token (parser->lexer)->location;
>>>
>>>To use warn_about_dialect_p.
>>
>>Ah yes.
>>
>>And just above that there's another pedwarn about a C++14 feature
>>being used:
>>
>>
>>      /* Default arguments shall not be specified in the
>>      parameter-declaration-clause of a lambda-declarator.  */
>>      if (cxx_dialect < cxx14)
>>     for (tree t = param_list; t; t = TREE_CHAIN (t))
>>       if (TREE_PURPOSE (t) && DECL_P (TREE_VALUE (t)))
>>         pedwarn (DECL_SOURCE_LOCATION (TREE_VALUE (t)), OPT_Wpedantic,
>>              "default argument specified for lambda parameter");
>>
>>
>>I didn't notice that one initially. That should also use
>>warn_about_dialect_p and OPT_Wc__14_extensions.
>
>Indeed.
>
>>Should I change the message to say "init capture" rather than
>>"default argument"?
>
>No, this is about e.g. [](int = 42){}

OK, this is a simpler version of the patch, with docs now, but without
the new warn_about_cxx_dialect_p function (which isn't needed) and
with no changes to any actual warning text (I'll do that separately,
if at all).

I also caught a few more pedwarn cases that I missed previously.

Tested powerpc64le-linux. OK for trunk?




[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 28502 bytes --]

commit 01daea63635cff592f3fdbe7be2b704843b9193c
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed May 19 21:35:58 2021

    c++: Add new warning options for C++ language mismatches
    
    This adds new warning flags, enabled by default: -Wc++11-extensions,
    -Wc++14-extensions, -Wc++17-extensions, -Wc++20-extensions, and
    -Wc++23-extensions. The names of the flags are copied from Clang, which
    already has similar options.
    
    No new diagnostics are added, but the new OPT_Wxxx variables are used to
    control existing pedwarns about occurences of new C++ constructs in code
    using an old C++ standard dialect. This allows several existing warnings
    that cannot currently be disabled to be controlled by the appropriate
    -Wno-xxx flag. For example, it will now be possible to disable warnings
    about using variadic templates in C++98 code, by using the new
    -Wno-c++11-extensions option. This will allow libstdc++ headers to
    disable those warnings unconditionally by using diagnostic pragmas, so
    that they are not emitted even if -Wsystem-headers is used.
    
    Some of the affected diagnostics are currently only given when
    -Wpedantic is used. Now that we have a more specific warning flag, we
    could consider making them not depend on -Wpedantic, and only on the new
    flag. This patch does not do that, as it intends to make no changes to
    what is accepted/rejected by default. The only effect should be that
    the new option is shown when -fdiagnostics-show-option is active, and
    that some warnings can be disabled by using the new flags (and for the
    warnings that previously only dependend on -Wpedantic, it will now be
    possible to disable just those warnings while still using -Wpedantic for
    its other benefits).
    
    gcc/c-family/ChangeLog:
    
            * c.opt (Wc++11-extensions, Wc++14-extensions)
            (Wc++17-extensions, Wc++20-extensions, Wc++23-extensions): New
            options.
    
    gcc/cp/ChangeLog:
    
            * call.c (maybe_warn_array_conv): Use new warning option.
            * decl.c (mark_inline_variable, grokdeclarator): Likewise.
            * error.c (maybe_warn_cpp0x): Likewise.
            * parser.c (cp_parser_primary_expression)
            (cp_parser_unqualified_id)
            (cp_parser_pseudo_destructor_name)
            (cp_parser_lambda_introducer)
            (cp_parser_lambda_declarator_opt)
            (cp_parser_selection_statement)
            (cp_parser_init_statement)
            (cp_parser_decomposition_declaration)
            (cp_parser_function_specifier_opt)
            (cp_parser_static_assert)
            (cp_parser_namespace_definition)
            (cp_parser_using_declaration)
            (cp_parser_asm_definition)
            (cp_parser_ctor_initializer_opt_and_function_body)
            (cp_parser_initializer_list)
            (cp_parser_type_parameter_key)
            (cp_parser_member_declaration)
            (cp_parser_try_block)
            (cp_parser_std_attribute_spec): Likewise.
            * pt.c (check_template_variable): Likewise.
    
    gcc/ChangeLog:
    
            * doc/invoke.texi (-Wno-c++11-extensions)
            (-Wno-c++14-extensions, -Wno-c++17-extensions)
            (-Wno-c++20-extensions, -Wno-c++23-extensions): Document
            new options.

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 5fcf961fd96..91929706aff 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -431,6 +431,26 @@ Wc++20-compat
 C++ ObjC++ Var(warn_cxx20_compat) Warning LangEnabledBy(C++ ObjC++,Wall)
 Warn about C++ constructs whose meaning differs between ISO C++ 2017 and ISO C++ 2020.
 
+Wc++11-extensions
+C++ ObjC++ Var(warn_cxx11_extensions) Warning LangEnabledBy(C++ ObjC++) Init(1)
+Warn about C++11 constructs in code compiled with an older standard.
+
+Wc++14-extensions
+C++ ObjC++ Var(warn_cxx14_extensions) Warning LangEnabledBy(C++ ObjC++) Init(1)
+Warn about C++14 constructs in code compiled with an older standard.
+
+Wc++17-extensions
+C++ ObjC++ Var(warn_cxx17_extensions) Warning LangEnabledBy(C++ ObjC++) Init(1)
+Warn about C++17 constructs in code compiled with an older standard.
+
+Wc++20-extensions
+C++ ObjC++ Var(warn_cxx20_extensions) Warning LangEnabledBy(C++ ObjC++) Init(1)
+Warn about C++20 constructs in code compiled with an older standard.
+
+Wc++23-extensions
+C++ ObjC++ Var(warn_cxx23_extensions) Warning LangEnabledBy(C++ ObjC++) Init(1)
+Warn about C++23 constructs in code compiled with an older standard.
+
 Wcast-function-type
 C ObjC C++ ObjC++ Var(warn_cast_function_type) Warning EnabledBy(Wextra)
 Warn about casts between incompatible function types.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 4a59b97c110..fa770f244cb 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -7469,8 +7469,9 @@ maybe_warn_array_conv (location_t loc, conversion *c, tree expr)
       || TYPE_DOMAIN (type) == NULL_TREE)
     return;
 
-  if (conv_binds_to_array_of_unknown_bound (c))
-    pedwarn (loc, OPT_Wpedantic, "conversions to arrays of unknown bound "
+  if (pedantic && conv_binds_to_array_of_unknown_bound (c))
+    pedwarn (loc, OPT_Wc__20_extensions,
+	     "conversions to arrays of unknown bound "
 	     "are only available with %<-std=c++20%> or %<-std=gnu++20%>");
 }
 
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 28052df9f45..7c32f09cf0e 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -11166,7 +11166,7 @@ mark_inline_variable (tree decl, location_t loc)
       inlinep = false;
     }
   else if (cxx_dialect < cxx17)
-    pedwarn (loc, 0, "inline variables are only available "
+    pedwarn (loc, OPT_Wc__17_extensions, "inline variables are only available "
 	     "with %<-std=c++17%> or %<-std=gnu++17%>");
   if (inlinep)
     {
@@ -12002,13 +12002,13 @@ grokdeclarator (const cp_declarator *declarator,
 	  storage_class = sc_none;
 	  staticp = 0;
 	}
-      if (constexpr_p && cxx_dialect < cxx20)
+      if (constexpr_p && pedantic && cxx_dialect < cxx20)
 	{
 	  gcc_rich_location richloc (declspecs->locations[ds_virtual]);
 	  richloc.add_range (declspecs->locations[ds_constexpr]);
-	  pedwarn (&richloc, OPT_Wpedantic, "member %qD can be declared both "
-		   "%<virtual%> and %<constexpr%> only in %<-std=c++20%> or "
-		   "%<-std=gnu++20%>", dname);
+	  pedwarn (&richloc, OPT_Wc__20_extensions, "member %qD can be "
+		   "declared both %<virtual%> and %<constexpr%> only in "
+		   "%<-std=c++20%> or %<-std=gnu++20%>", dname);
 	}
     }
   friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
@@ -12096,7 +12096,7 @@ grokdeclarator (const cp_declarator *declarator,
 	error_at (declspecs->locations[ds_consteval], "structured "
 		  "binding declaration cannot be %qs", "consteval");
       if (thread_p && cxx_dialect < cxx20)
-	pedwarn (declspecs->locations[ds_thread], 0,
+	pedwarn (declspecs->locations[ds_thread], OPT_Wc__20_extensions,
 		 "structured binding declaration can be %qs only in "
 		 "%<-std=c++20%> or %<-std=gnu++20%>",
 		 declspecs->gnu_thread_keyword_p
@@ -12118,7 +12118,7 @@ grokdeclarator (const cp_declarator *declarator,
 	  break;
 	case sc_static:
 	  if (cxx_dialect < cxx20)
-	    pedwarn (loc, 0,
+	    pedwarn (loc, OPT_Wc__20_extensions,
 		     "structured binding declaration can be %qs only in "
 		     "%<-std=c++20%> or %<-std=gnu++20%>", "static");
 	  break;
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 3c2276b1976..3d5eebd4bcd 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -4407,77 +4407,78 @@ maybe_warn_cpp0x (cpp0x_warn_str str)
     switch (str)
       {
       case CPP0X_INITIALIZER_LISTS:
-	pedwarn (input_location, 0, 
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "extended initializer lists "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_EXPLICIT_CONVERSION:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "explicit conversion operators "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_VARIADIC_TEMPLATES:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "variadic templates "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_LAMBDA_EXPR:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "lambda expressions "
 		  "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_AUTO:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "C++11 auto only available with %<-std=c++11%> or "
 		 "%<-std=gnu++11%>");
 	break;
       case CPP0X_SCOPED_ENUMS:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "scoped enums only available with %<-std=c++11%> or "
 		 "%<-std=gnu++11%>");
 	break;
       case CPP0X_DEFAULTED_DELETED:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "defaulted and deleted functions "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_INLINE_NAMESPACES:
-	pedwarn (input_location, OPT_Wpedantic,
-		 "inline namespaces "
-		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
+	if (pedantic)
+	  pedwarn (input_location, OPT_Wc__11_extensions,
+		   "inline namespaces "
+		   "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_OVERRIDE_CONTROLS:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "override controls (override/final) "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
         break;
       case CPP0X_NSDMI:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "non-static data member initializers "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
         break;
       case CPP0X_USER_DEFINED_LITERALS:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "user-defined literals "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_DELEGATING_CTORS:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "delegating constructors "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
         break;
       case CPP0X_INHERITING_CTORS:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "inheriting constructors "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
         break;
       case CPP0X_ATTRIBUTES:
-	pedwarn (input_location, 0,
-		 "c++11 attributes "
+	pedwarn (input_location, OPT_Wc__11_extensions,
+		 "C++11 attributes "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
       case CPP0X_REF_QUALIFIER:
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__11_extensions,
 		 "ref-qualifiers "
 		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
 	break;
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index bc0505df502..48b83d67b34 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -5577,8 +5577,9 @@ cp_parser_primary_expression (cp_parser *parser,
 	    expr = cp_parser_fold_expression (parser, expr);
 	    if (expr != error_mark_node
 		&& cxx_dialect < cxx17)
-	      pedwarn (input_location, 0, "fold-expressions only available "
-		       "with %<-std=c++17%> or %<-std=gnu++17%>");
+	      pedwarn (input_location, OPT_Wc__17_extensions,
+		       "fold-expressions only available with %<-std=c++17%> "
+		       "or %<-std=gnu++17%>");
 	  }
 	else
 	  /* Let the front end know that this expression was
@@ -6325,7 +6326,7 @@ cp_parser_unqualified_id (cp_parser* parser,
 	if (cp_parser_is_keyword (token, RID_AUTO))
 	  {
 	    if (cxx_dialect < cxx14)
-	      pedwarn (loc, 0,
+	      pedwarn (loc, OPT_Wc__14_extensions,
 		       "%<~auto%> only available with "
 		       "%<-std=c++14%> or %<-std=gnu++14%>");
 	    cp_lexer_consume_token (parser->lexer);
@@ -8353,7 +8354,7 @@ cp_parser_pseudo_destructor_name (cp_parser* parser,
       && !type_dependent_expression_p (object))
     {
       if (cxx_dialect < cxx14)
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__14_extensions,
 		 "%<~auto%> only available with "
 		 "%<-std=c++14%> or %<-std=gnu++14%>");
       cp_lexer_consume_token (parser->lexer);
@@ -11042,8 +11043,9 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
 	{
 	  location_t loc = cp_lexer_peek_token (parser->lexer)->location;
 	  if (cxx_dialect < cxx17)
-	    pedwarn (loc, 0, "%<*this%> capture only available with "
-			     "%<-std=c++17%> or %<-std=gnu++17%>");
+	    pedwarn (loc, OPT_Wc__17_extensions,
+		     "%<*this%> capture only available with "
+		     "%<-std=c++17%> or %<-std=gnu++17%>");
 	  cp_lexer_consume_token (parser->lexer);
 	  cp_lexer_consume_token (parser->lexer);
 	  if (LAMBDA_EXPR_THIS_CAPTURE (lambda_expr))
@@ -11081,7 +11083,8 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
 	{
 	  ellipsis_loc = cp_lexer_peek_token (parser->lexer)->location;
 	  if (cxx_dialect < cxx20)
-	    pedwarn (ellipsis_loc, 0, "pack init-capture only available with "
+	    pedwarn (ellipsis_loc, OPT_Wc__20_extensions,
+		     "pack init-capture only available with "
 		     "%<-std=c++20%> or %<-std=gnu++20%>");
 	  cp_lexer_consume_token (parser->lexer);
 	  init_pack_expansion = true;
@@ -11122,7 +11125,7 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
 	  bool direct, non_constant;
 	  /* An explicit initializer exists.  */
 	  if (cxx_dialect < cxx14)
-	    pedwarn (input_location, 0,
+	    pedwarn (input_location, OPT_Wc__14_extensions,
 		     "lambda capture initializers "
 		     "only available with %<-std=c++14%> or %<-std=gnu++14%>");
 	  capture_init_expr = cp_parser_initializer (parser, &direct,
@@ -11296,11 +11299,11 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
   if (cp_lexer_next_token_is (parser->lexer, CPP_LESS))
     {
       if (cxx_dialect < cxx14)
-	pedwarn (parser->lexer->next_token->location, 0,
+	pedwarn (parser->lexer->next_token->location, OPT_Wc__14_extensions,
 		 "lambda templates are only available with "
 		 "%<-std=c++14%> or %<-std=gnu++14%>");
-      else if (cxx_dialect < cxx20)
-	pedwarn (parser->lexer->next_token->location, OPT_Wpedantic,
+      else if (pedantic && cxx_dialect < cxx20)
+	pedwarn (parser->lexer->next_token->location, OPT_Wc__20_extensions,
 		 "lambda templates are only available with "
 		 "%<-std=c++20%> or %<-std=gnu++20%>");
 
@@ -11365,10 +11368,11 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
 
       /* Default arguments shall not be specified in the
 	 parameter-declaration-clause of a lambda-declarator.  */
-      if (cxx_dialect < cxx14)
+      if (pedantic && cxx_dialect < cxx14)
 	for (tree t = param_list; t; t = TREE_CHAIN (t))
 	  if (TREE_PURPOSE (t) && DECL_P (TREE_VALUE (t)))
-	    pedwarn (DECL_SOURCE_LOCATION (TREE_VALUE (t)), OPT_Wpedantic,
+	    pedwarn (DECL_SOURCE_LOCATION (TREE_VALUE (t)),
+		     OPT_Wc__14_extensions,
 		     "default argument specified for lambda parameter");
 
       parens.require_close (parser);
@@ -11388,7 +11392,7 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
 
   if (omitted_parms_loc && lambda_specs.any_specifiers_p)
     {
-      pedwarn (omitted_parms_loc, 0,
+      pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
 	       "parameter declaration before lambda declaration "
 	       "specifiers only optional with %<-std=c++2b%> or "
 	       "%<-std=gnu++2b%>");
@@ -11407,7 +11411,7 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
   tx_qual = cp_parser_tx_qualifier_opt (parser);
   if (omitted_parms_loc && tx_qual)
     {
-      pedwarn (omitted_parms_loc, 0,
+      pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
 	       "parameter declaration before lambda transaction "
 	       "qualifier only optional with %<-std=c++2b%> or "
 	       "%<-std=gnu++2b%>");
@@ -11420,7 +11424,7 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
 
   if (omitted_parms_loc && exception_spec)
     {
-      pedwarn (omitted_parms_loc, 0,
+      pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
 	       "parameter declaration before lambda exception "
 	       "specification only optional with %<-std=c++2b%> or "
 	       "%<-std=gnu++2b%>");
@@ -11438,7 +11442,7 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
   if (cp_lexer_next_token_is (parser->lexer, CPP_DEREF))
     {
       if (omitted_parms_loc)
-	pedwarn (omitted_parms_loc, 0,
+	pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
 		 "parameter declaration before lambda trailing "
 		 "return type only optional with %<-std=c++2b%> or "
 		 "%<-std=gnu++2b%>");
@@ -12301,8 +12305,9 @@ cp_parser_selection_statement (cp_parser* parser, bool *if_p,
 	    cx = true;
 	    cp_token *tok = cp_lexer_consume_token (parser->lexer);
 	    if (cxx_dialect < cxx17)
-	      pedwarn (tok->location, 0, "%<if constexpr%> only available "
-		       "with %<-std=c++17%> or %<-std=gnu++17%>");
+	      pedwarn (tok->location, OPT_Wc__17_extensions,
+		       "%<if constexpr%> only available with "
+		       "%<-std=c++17%> or %<-std=gnu++17%>");
 	  }
 
 	/* Look for the `('.  */
@@ -12327,7 +12332,8 @@ cp_parser_selection_statement (cp_parser* parser, bool *if_p,
 	  {
 	    tree decl;
 	    if (cxx_dialect < cxx17)
-	      pedwarn (cp_lexer_peek_token (parser->lexer)->location, 0,
+	      pedwarn (cp_lexer_peek_token (parser->lexer)->location,
+		       OPT_Wc__17_extensions,
 		       "init-statement in selection statements only available "
 		       "with %<-std=c++17%> or %<-std=gnu++17%>");
 	    if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
@@ -13398,7 +13404,8 @@ cp_parser_init_statement (cp_parser *parser, tree *decl)
 
 	  if (cxx_dialect < cxx20)
 	    {
-	      pedwarn (cp_lexer_peek_token (parser->lexer)->location, 0,
+	      pedwarn (cp_lexer_peek_token (parser->lexer)->location,
+		       OPT_Wc__20_extensions,
 		       "range-based %<for%> loops with initializer only "
 		       "available with %<-std=c++20%> or %<-std=gnu++20%>");
 	      *decl = error_mark_node;
@@ -13422,7 +13429,8 @@ cp_parser_init_statement (cp_parser *parser, tree *decl)
 	  cp_lexer_consume_token (parser->lexer);
 	  is_range_for = true;
 	  if (cxx_dialect < cxx11)
-	    pedwarn (cp_lexer_peek_token (parser->lexer)->location, 0,
+	    pedwarn (cp_lexer_peek_token (parser->lexer)->location,
+		     OPT_Wc__11_extensions,
 		     "range-based %<for%> loops only available with "
 		     "%<-std=c++11%> or %<-std=gnu++11%>");
 	}
@@ -14665,8 +14673,9 @@ cp_parser_decomposition_declaration (cp_parser *parser,
     }
 
   if (cxx_dialect < cxx17)
-    pedwarn (loc, 0, "structured bindings only available with "
-		     "%<-std=c++17%> or %<-std=gnu++17%>");
+    pedwarn (loc, OPT_Wc__17_extensions,
+	     "structured bindings only available with "
+	     "%<-std=c++17%> or %<-std=gnu++17%>");
 
   tree pushed_scope;
   cp_declarator *declarator = make_declarator (cdk_decomp);
@@ -15261,7 +15270,7 @@ cp_parser_function_specifier_opt (cp_parser* parser,
 	      = G_("types may not be defined in explicit-specifier");
 
 	    if (cxx_dialect < cxx20)
-	      pedwarn (token->location, 0,
+	      pedwarn (token->location, OPT_Wc__20_extensions,
 		       "%<explicit(bool)%> only available with %<-std=c++20%> "
 		       "or %<-std=gnu++20%>");
 
@@ -15428,8 +15437,8 @@ cp_parser_static_assert(cp_parser *parser, bool member_p)
 
   if (cp_lexer_peek_token (parser->lexer)->type == CPP_CLOSE_PAREN)
     {
-      if (cxx_dialect < cxx17)
-	pedwarn (input_location, OPT_Wpedantic,
+      if (pedantic && cxx_dialect < cxx17)
+	pedwarn (input_location, OPT_Wc__17_extensions,
 		 "%<static_assert%> without a message "
 		 "only available with %<-std=c++17%> or %<-std=gnu++17%>");
       /* Eat the ')'  */
@@ -20418,10 +20427,11 @@ cp_parser_namespace_definition (cp_parser* parser)
 							     RID_INLINE);
       if (nested_inline_p && nested_definition_count != 0)
 	{
-	  if (cxx_dialect < cxx20)
+	  if (pedantic && cxx_dialect < cxx20)
 	    pedwarn (cp_lexer_peek_token (parser->lexer)->location,
-		     OPT_Wpedantic, "nested inline namespace definitions only "
-		     "available with %<-std=c++20%> or %<-std=gnu++20%>");
+		     OPT_Wc__20_extensions, "nested inline namespace "
+		     "definitions only available with %<-std=c++20%> or "
+		     "%<-std=gnu++20%>");
 	  cp_lexer_consume_token (parser->lexer);
 	}
 
@@ -20448,8 +20458,8 @@ cp_parser_namespace_definition (cp_parser* parser)
 	  break;
 	}
 
-      if (!nested_definition_count && cxx_dialect < cxx17)
-        pedwarn (input_location, OPT_Wpedantic,
+      if (!nested_definition_count && pedantic && cxx_dialect < cxx17)
+        pedwarn (input_location, OPT_Wc__17_extensions,
 		 "nested namespace definitions only available with "
 		 "%<-std=c++17%> or %<-std=gnu++17%>");
 
@@ -20708,7 +20718,7 @@ cp_parser_using_declaration (cp_parser* parser,
     {
       cp_token *ell = cp_lexer_consume_token (parser->lexer);
       if (cxx_dialect < cxx17)
-	pedwarn (ell->location, 0,
+	pedwarn (ell->location, OPT_Wc__17_extensions,
 		 "pack expansion in using-declaration only available "
 		 "with %<-std=c++17%> or %<-std=gnu++17%>");
       qscope = make_pack_expansion (qscope);
@@ -20741,7 +20751,7 @@ cp_parser_using_declaration (cp_parser* parser,
     {
       cp_token *comma = cp_lexer_consume_token (parser->lexer);
       if (cxx_dialect < cxx17)
-	pedwarn (comma->location, 0,
+	pedwarn (comma->location, OPT_Wc__17_extensions,
 		 "comma-separated list in using-declaration only available "
 		 "with %<-std=c++17%> or %<-std=gnu++17%>");
       goto again;
@@ -21057,9 +21067,10 @@ cp_parser_asm_definition (cp_parser* parser)
      functions.  */
   if (parser->in_function_body
       && DECL_DECLARED_CONSTEXPR_P (current_function_decl)
-      && (cxx_dialect < cxx20))
-    pedwarn (asm_loc, 0, "%<asm%> in %<constexpr%> function only available "
-	     "with %<-std=c++20%> or %<-std=gnu++20%>");
+      && cxx_dialect < cxx20)
+    pedwarn (asm_loc, OPT_Wc__20_extensions, "%<asm%> in %<constexpr%> "
+	     "function only available with %<-std=c++20%> or "
+	     "%<-std=gnu++20%>");
 
   /* Handle the asm-qualifier-list.  */
   location_t volatile_loc = UNKNOWN_LOCATION;
@@ -24131,11 +24142,11 @@ cp_parser_ctor_initializer_opt_and_function_body (cp_parser *parser,
       && cxx_dialect < cxx20)
     {
       if (DECL_CONSTRUCTOR_P (current_function_decl))
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__20_extensions,
 		 "function-try-block body of %<constexpr%> constructor only "
 		 "available with %<-std=c++20%> or %<-std=gnu++20%>");
       else
-	pedwarn (input_location, 0,
+	pedwarn (input_location, OPT_Wc__20_extensions,
 		 "function-try-block body of %<constexpr%> function only "
 		 "available with %<-std=c++20%> or %<-std=gnu++20%>");
     }
@@ -24458,8 +24469,8 @@ cp_parser_initializer_list (cp_parser* parser, bool* non_constant_p,
 	      || (cp_lexer_peek_nth_token (parser->lexer, 3)->type
 		  == CPP_OPEN_BRACE)))
 	{
-	  if (cxx_dialect < cxx20)
-	    pedwarn (loc, OPT_Wpedantic,
+	  if (pedantic && cxx_dialect < cxx20)
+	    pedwarn (loc, OPT_Wc__20_extensions,
 		     "C++ designated initializers only available with "
 		     "%<-std=c++20%> or %<-std=gnu++20%>");
 	  /* Consume the `.'.  */
@@ -25800,10 +25811,11 @@ cp_parser_type_parameter_key (cp_parser* parser)
   if ((tag_type = cp_parser_token_is_type_parameter_key (token)) != none_type)
     {
       cp_lexer_consume_token (parser->lexer);
-      if (pedantic && tag_type == typename_type && cxx_dialect < cxx17)
+      if (pedantic && tag_type == typename_type
+	  && cxx_dialect < cxx17)
 	/* typename is not allowed in a template template parameter
 	   by the standard until C++17.  */
-	pedwarn (token->location, OPT_Wpedantic,
+	pedwarn (token->location, OPT_Wc__17_extensions,
 		 "ISO C++ forbids typename key in template template parameter;"
 		 " use %<-std=c++17%> or %<-std=gnu++17%>");
     }
@@ -26197,7 +26209,7 @@ cp_parser_member_declaration (cp_parser* parser)
 		    = cp_lexer_peek_token (parser->lexer)->location;
 		  if (cxx_dialect < cxx20
 		      && identifier != NULL_TREE)
-		    pedwarn (loc, 0,
+		    pedwarn (loc, OPT_Wc__20_extensions,
 			     "default member initializers for bit-fields "
 			     "only available with %<-std=c++20%> or "
 			     "%<-std=gnu++20%>");
@@ -27158,7 +27170,7 @@ cp_parser_try_block (cp_parser* parser)
   if (parser->in_function_body
       && DECL_DECLARED_CONSTEXPR_P (current_function_decl)
       && cxx_dialect < cxx20)
-    pedwarn (input_location, 0,
+    pedwarn (input_location, OPT_Wc__20_extensions,
 	     "%<try%> in %<constexpr%> function only "
 	     "available with %<-std=c++20%> or %<-std=gnu++20%>");
 
@@ -28117,7 +28129,7 @@ cp_parser_std_attribute_spec (cp_parser *parser)
 	      && cp_lexer_nth_token_is (parser->lexer, 3, CPP_COLON))
 	    {
 	      if (cxx_dialect < cxx17)
-		pedwarn (input_location, 0,
+		pedwarn (input_location, OPT_Wc__17_extensions,
 			 "attribute using prefix only available "
 			 "with %<-std=c++17%> or %<-std=gnu++17%>");
 
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index cbd2f3dc338..3d1787b6fc3 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -2703,7 +2703,7 @@ check_template_variable (tree decl)
       && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl)))
     {
       if (cxx_dialect < cxx14)
-        pedwarn (DECL_SOURCE_LOCATION (decl), 0,
+        pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wc__14_extensions,
 		 "variable templates only available with "
 		 "%<-std=c++14%> or %<-std=gnu++14%>");
 
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 49c74f37497..9bcbcdc777c 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -330,7 +330,9 @@ Objective-C and Objective-C++ Dialects}.
 -Wno-builtin-macro-redefined  -Wc90-c99-compat  -Wc99-c11-compat @gol
 -Wc11-c2x-compat @gol
 -Wc++-compat  -Wc++11-compat  -Wc++14-compat  -Wc++17-compat  @gol
--Wc++20-compat  @gol
+-Wc++20-compat   @gol
+-Wno-c++11-extensions  -Wno-c++14-extensions -Wno-c++17-extensions  @gol
+-Wno-c++20-extensions  -Wno-c++23-extensions  @gol
 -Wcast-align  -Wcast-align=strict  -Wcast-function-type  -Wcast-qual  @gol
 -Wchar-subscripts @gol
 -Wclobbered  -Wcomment @gol
@@ -8154,6 +8156,41 @@ and ISO C++ 2017.  This warning is enabled by @option{-Wall}.
 Warn about C++ constructs whose meaning differs between ISO C++ 2017
 and ISO C++ 2020.  This warning is enabled by @option{-Wall}.
 
+@item -Wno-c++11-extensions @r{(C++ and Objective-C++ only)}
+@opindex Wc++11-extensions
+@opindex Wno-c++11-extensions
+Do not warn about C++11 constructs in code being compiled using
+an older C++ standard.  Even without this option, some C++11 constructs
+will only be diagnosed if @option{-Wpedantic} is used.
+
+@item -Wno-c++14-extensions @r{(C++ and Objective-C++ only)}
+@opindex Wc++14-extensions
+@opindex Wno-c++14-extensions
+Do not warn about C++14 constructs in code being compiled using
+an older C++ standard.  Even without this option, some C++14 constructs
+will only be diagnosed if @option{-Wpedantic} is used.
+
+@item -Wno-c++17-extensions @r{(C++ and Objective-C++ only)}
+@opindex Wc++17-extensions
+@opindex Wno-c++17-extensions
+Do not warn about C++17 constructs in code being compiled using
+an older C++ standard.  Even without this option, some C++17 constructs
+will only be diagnosed if @option{-Wpedantic} is used.
+
+@item -Wno-c++20-extensions @r{(C++ and Objective-C++ only)}
+@opindex Wc++20-extensions
+@opindex Wno-c++20-extensions
+Do not warn about C++20 constructs in code being compiled using
+an older C++ standard.  Even without this option, some C++20 constructs
+will only be diagnosed if @option{-Wpedantic} is used.
+
+@item -Wno-c++23-extensions @r{(C++ and Objective-C++ only)}
+@opindex Wc++23-extensions
+@opindex Wno-c++23-extensions
+Do not warn about C++23 constructs in code being compiled using
+an older C++ standard.  Even without this option, some C++23 constructs
+will only be diagnosed if @option{-Wpedantic} is used.
+
 @item -Wcast-qual
 @opindex Wcast-qual
 @opindex Wno-cast-qual

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-20 12:56           ` Jonathan Wakely
@ 2021-05-20 16:34             ` Jason Merrill
  2021-05-20 19:49               ` Jonathan Wakely
  2021-05-20 17:25             ` Martin Sebor
  1 sibling, 1 reply; 31+ messages in thread
From: Jason Merrill @ 2021-05-20 16:34 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-patches, Marek Polacek, Martin Sebor

On 5/20/21 8:56 AM, Jonathan Wakely wrote:
> On 19/05/21 16:05 -0400, Jason Merrill wrote:
>> On 5/19/21 3:55 PM, Jonathan Wakely wrote:
>>> On 19/05/21 13:26 -0400, Jason Merrill wrote:
>>>> On 5/19/21 12:46 PM, Jonathan Wakely wrote:
>>>>> On 19/05/21 17:39 +0100, Jonathan Wakely wrote:
>>>>>> Jakub pointed out I'd forgotten the spaces before the opening parens
>>>>>> for function calls. The attached patch should fix all those, with no
>>>>>> other changes.
>>>>>>
>>>>>> Tested x86_64-linux. OK for trunk?
>>>>>
>>>>> Jakub also pointed out we already have some similar diagnostics for
>>>>> C++23, but I missed them as they say "only optional with" not "only
>>>>> available with".
>>>>>
>>>>> I'm testing the incremental change in the attached patch which also
>>>>> adds -Wc++23-extensions, and I'll resend the full patch after that
>>>>> finishes.
>>>>
>>>>>   if (omitted_parms_loc && lambda_specs.any_specifiers_p)
>>>>>     {
>>>>> -      pedwarn (omitted_parms_loc, 0,
>>>>> +      pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
>>>>
>>>> You probably want to change
>>>>
>>>>>  else if (cxx_dialect < cxx23)
>>>>>    omitted_parms_loc = cp_lexer_peek_token (parser->lexer)->location;
>>>>
>>>> To use warn_about_dialect_p.
>>>
>>> Ah yes.
>>>
>>> And just above that there's another pedwarn about a C++14 feature
>>> being used:
>>>
>>>
>>>      /* Default arguments shall not be specified in the
>>>      parameter-declaration-clause of a lambda-declarator.  */
>>>      if (cxx_dialect < cxx14)
>>>     for (tree t = param_list; t; t = TREE_CHAIN (t))
>>>       if (TREE_PURPOSE (t) && DECL_P (TREE_VALUE (t)))
>>>         pedwarn (DECL_SOURCE_LOCATION (TREE_VALUE (t)), OPT_Wpedantic,
>>>              "default argument specified for lambda parameter");
>>>
>>>
>>> I didn't notice that one initially. That should also use
>>> warn_about_dialect_p and OPT_Wc__14_extensions.
>>
>> Indeed.
>>
>>> Should I change the message to say "init capture" rather than
>>> "default argument"?
>>
>> No, this is about e.g. [](int = 42){}
> 
> OK, this is a simpler version of the patch, with docs now, but without
> the new warn_about_cxx_dialect_p function (which isn't needed) and
> with no changes to any actual warning text (I'll do that separately,
> if at all).
> 
> I also caught a few more pedwarn cases that I missed previously.
> 
> Tested powerpc64le-linux. OK for trunk?

OK.  Do we also want, say, -Wno-std-extensions to turn them all off at once?

Jason


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-20 12:56           ` Jonathan Wakely
  2021-05-20 16:34             ` Jason Merrill
@ 2021-05-20 17:25             ` Martin Sebor
  2021-05-20 19:32               ` Jonathan Wakely
  1 sibling, 1 reply; 31+ messages in thread
From: Martin Sebor @ 2021-05-20 17:25 UTC (permalink / raw)
  To: Jonathan Wakely, Jason Merrill; +Cc: gcc-patches, Marek Polacek

On 5/20/21 6:56 AM, Jonathan Wakely wrote:
> On 19/05/21 16:05 -0400, Jason Merrill wrote:
>> On 5/19/21 3:55 PM, Jonathan Wakely wrote:
>>> On 19/05/21 13:26 -0400, Jason Merrill wrote:
>>>> On 5/19/21 12:46 PM, Jonathan Wakely wrote:
>>>>> On 19/05/21 17:39 +0100, Jonathan Wakely wrote:
>>>>>> Jakub pointed out I'd forgotten the spaces before the opening parens
>>>>>> for function calls. The attached patch should fix all those, with no
>>>>>> other changes.
>>>>>>
>>>>>> Tested x86_64-linux. OK for trunk?
>>>>>
>>>>> Jakub also pointed out we already have some similar diagnostics for
>>>>> C++23, but I missed them as they say "only optional with" not "only
>>>>> available with".
>>>>>
>>>>> I'm testing the incremental change in the attached patch which also
>>>>> adds -Wc++23-extensions, and I'll resend the full patch after that
>>>>> finishes.
>>>>
>>>>>   if (omitted_parms_loc && lambda_specs.any_specifiers_p)
>>>>>     {
>>>>> -      pedwarn (omitted_parms_loc, 0,
>>>>> +      pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
>>>>
>>>> You probably want to change
>>>>
>>>>>  else if (cxx_dialect < cxx23)
>>>>>    omitted_parms_loc = cp_lexer_peek_token (parser->lexer)->location;
>>>>
>>>> To use warn_about_dialect_p.
>>>
>>> Ah yes.
>>>
>>> And just above that there's another pedwarn about a C++14 feature
>>> being used:
>>>
>>>
>>>      /* Default arguments shall not be specified in the
>>>      parameter-declaration-clause of a lambda-declarator.  */
>>>      if (cxx_dialect < cxx14)
>>>     for (tree t = param_list; t; t = TREE_CHAIN (t))
>>>       if (TREE_PURPOSE (t) && DECL_P (TREE_VALUE (t)))
>>>         pedwarn (DECL_SOURCE_LOCATION (TREE_VALUE (t)), OPT_Wpedantic,
>>>              "default argument specified for lambda parameter");
>>>
>>>
>>> I didn't notice that one initially. That should also use
>>> warn_about_dialect_p and OPT_Wc__14_extensions.
>>
>> Indeed.
>>
>>> Should I change the message to say "init capture" rather than
>>> "default argument"?
>>
>> No, this is about e.g. [](int = 42){}
> 
> OK, this is a simpler version of the patch, with docs now, but without
> the new warn_about_cxx_dialect_p function (which isn't needed) and
> with no changes to any actual warning text (I'll do that separately,
> if at all).
> 
> I also caught a few more pedwarn cases that I missed previously.
> 
> Tested powerpc64le-linux. OK for trunk?

This looks good to me, and the change overall simpler.  Just one
minor thing (sorry if that seems nit-picky): in the last sentence
in the documentation, does "this option" refer to the -Wc++11 form
or to the negative? (The latter is the one that's going to be
mentioned in the entry.)

If what the sentence is trying to say is that warnings for some C++
11 constructs are controlled only by -Wpedantic then I'd suggest to
rephrase it to make that part clearer (or drop it altogether since
it sounds like it describes a limitation/problem that we might want
to work toward fixing).

@@ -8154,6 +8156,41 @@ and ISO C++ 2017.  This warning is enabled by 
@option{-Wall}.
  Warn about C++ constructs whose meaning differs between ISO C++ 2017
  and ISO C++ 2020.  This warning is enabled by @option{-Wall}.

+@item -Wno-c++11-extensions @r{(C++ and Objective-C++ only)}
+@opindex Wc++11-extensions
+@opindex Wno-c++11-extensions
+Do not warn about C++11 constructs in code being compiled using
+an older C++ standard.  Even without this option, some C++11 constructs
+will only be diagnosed if @option{-Wpedantic} is used.

Martin

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-20 17:25             ` Martin Sebor
@ 2021-05-20 19:32               ` Jonathan Wakely
  0 siblings, 0 replies; 31+ messages in thread
From: Jonathan Wakely @ 2021-05-20 19:32 UTC (permalink / raw)
  To: Martin Sebor; +Cc: Jason Merrill, gcc-patches, Marek Polacek

On 20/05/21 11:25 -0600, Martin Sebor wrote:
>On 5/20/21 6:56 AM, Jonathan Wakely wrote:
>>On 19/05/21 16:05 -0400, Jason Merrill wrote:
>>>On 5/19/21 3:55 PM, Jonathan Wakely wrote:
>>>>On 19/05/21 13:26 -0400, Jason Merrill wrote:
>>>>>On 5/19/21 12:46 PM, Jonathan Wakely wrote:
>>>>>>On 19/05/21 17:39 +0100, Jonathan Wakely wrote:
>>>>>>>Jakub pointed out I'd forgotten the spaces before the opening parens
>>>>>>>for function calls. The attached patch should fix all those, with no
>>>>>>>other changes.
>>>>>>>
>>>>>>>Tested x86_64-linux. OK for trunk?
>>>>>>
>>>>>>Jakub also pointed out we already have some similar diagnostics for
>>>>>>C++23, but I missed them as they say "only optional with" not "only
>>>>>>available with".
>>>>>>
>>>>>>I'm testing the incremental change in the attached patch which also
>>>>>>adds -Wc++23-extensions, and I'll resend the full patch after that
>>>>>>finishes.
>>>>>
>>>>>>  if (omitted_parms_loc && lambda_specs.any_specifiers_p)
>>>>>>    {
>>>>>>-      pedwarn (omitted_parms_loc, 0,
>>>>>>+      pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
>>>>>
>>>>>You probably want to change
>>>>>
>>>>>> else if (cxx_dialect < cxx23)
>>>>>>   omitted_parms_loc = cp_lexer_peek_token (parser->lexer)->location;
>>>>>
>>>>>To use warn_about_dialect_p.
>>>>
>>>>Ah yes.
>>>>
>>>>And just above that there's another pedwarn about a C++14 feature
>>>>being used:
>>>>
>>>>
>>>>     /* Default arguments shall not be specified in the
>>>>     parameter-declaration-clause of a lambda-declarator.  */
>>>>     if (cxx_dialect < cxx14)
>>>>    for (tree t = param_list; t; t = TREE_CHAIN (t))
>>>>      if (TREE_PURPOSE (t) && DECL_P (TREE_VALUE (t)))
>>>>        pedwarn (DECL_SOURCE_LOCATION (TREE_VALUE (t)), OPT_Wpedantic,
>>>>             "default argument specified for lambda parameter");
>>>>
>>>>
>>>>I didn't notice that one initially. That should also use
>>>>warn_about_dialect_p and OPT_Wc__14_extensions.
>>>
>>>Indeed.
>>>
>>>>Should I change the message to say "init capture" rather than
>>>>"default argument"?
>>>
>>>No, this is about e.g. [](int = 42){}
>>
>>OK, this is a simpler version of the patch, with docs now, but without
>>the new warn_about_cxx_dialect_p function (which isn't needed) and
>>with no changes to any actual warning text (I'll do that separately,
>>if at all).
>>
>>I also caught a few more pedwarn cases that I missed previously.
>>
>>Tested powerpc64le-linux. OK for trunk?
>
>This looks good to me, and the change overall simpler.  Just one
>minor thing (sorry if that seems nit-picky): in the last sentence
>in the documentation, does "this option" refer to the -Wc++11 form
>or to the negative? (The latter is the one that's going to be
>mentioned in the entry.)

It refers to the form documented, the -Wno- one.

To give a specific example, warnings about variadic templates in C++98
are enabled by default, and disabled by -Wno-c++11-extensions. But
warnings about inline namespaces in C++98 are *not* enabled by
default, only if you use -Wpedantic. -Wno-c++11-extensions still
silences them when you do use -Wpedantic, it's just not needed to
suppress them by default.


>If what the sentence is trying to say is that warnings for some C++
>11 constructs are controlled only by -Wpedantic then I'd suggest to

No, not _only_ by -Wpedantic. They depend on both -Wpedantic and
-Wc++11-extensions. Some warnings are not emitted by default, only
when -Wpedantic is used. When -Wpedantic _is_ used, you can use
-Wno-c++11-extensions to suppress them again (without suppressing all
the other warnings that -Wpedantic enables).

>rephrase it to make that part clearer (or drop it altogether since
>it sounds like it describes a limitation/problem that we might want
>to work toward fixing).

I think the doc text is accurate, but it seems it could be clearer so
that's it's both accurate and easy to understand. I'm open to
suggestions.

At one point I did include the specific examples given above, so it
read something like this:


-Wno-c++11-extensions (C++ and Objective-C++ only)

Do not warn about C++11 constructs in code being compiled using an
older C++ standard, e.g., disable warnings about using variadic
templates in C++98 code.  Even without this option, some C++11
constructs will only be diagnosed if @option{-Wpedantic} is used,
e.g., by default there are no warnings about inline namespaces in
C++98 code, only when -Wpedantic is used.  The -Wno-c++11-extensions
option disables those warnings when -Wpedantic is used.



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-20 16:34             ` Jason Merrill
@ 2021-05-20 19:49               ` Jonathan Wakely
  0 siblings, 0 replies; 31+ messages in thread
From: Jonathan Wakely @ 2021-05-20 19:49 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches, Marek Polacek, Martin Sebor

On 20/05/21 12:34 -0400, Jason Merrill wrote:
>On 5/20/21 8:56 AM, Jonathan Wakely wrote:
>>On 19/05/21 16:05 -0400, Jason Merrill wrote:
>>>On 5/19/21 3:55 PM, Jonathan Wakely wrote:
>>>>On 19/05/21 13:26 -0400, Jason Merrill wrote:
>>>>>On 5/19/21 12:46 PM, Jonathan Wakely wrote:
>>>>>>On 19/05/21 17:39 +0100, Jonathan Wakely wrote:
>>>>>>>Jakub pointed out I'd forgotten the spaces before the opening parens
>>>>>>>for function calls. The attached patch should fix all those, with no
>>>>>>>other changes.
>>>>>>>
>>>>>>>Tested x86_64-linux. OK for trunk?
>>>>>>
>>>>>>Jakub also pointed out we already have some similar diagnostics for
>>>>>>C++23, but I missed them as they say "only optional with" not "only
>>>>>>available with".
>>>>>>
>>>>>>I'm testing the incremental change in the attached patch which also
>>>>>>adds -Wc++23-extensions, and I'll resend the full patch after that
>>>>>>finishes.
>>>>>
>>>>>>  if (omitted_parms_loc && lambda_specs.any_specifiers_p)
>>>>>>    {
>>>>>>-      pedwarn (omitted_parms_loc, 0,
>>>>>>+      pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
>>>>>
>>>>>You probably want to change
>>>>>
>>>>>> else if (cxx_dialect < cxx23)
>>>>>>   omitted_parms_loc = cp_lexer_peek_token (parser->lexer)->location;
>>>>>
>>>>>To use warn_about_dialect_p.
>>>>
>>>>Ah yes.
>>>>
>>>>And just above that there's another pedwarn about a C++14 feature
>>>>being used:
>>>>
>>>>
>>>>     /* Default arguments shall not be specified in the
>>>>     parameter-declaration-clause of a lambda-declarator.  */
>>>>     if (cxx_dialect < cxx14)
>>>>    for (tree t = param_list; t; t = TREE_CHAIN (t))
>>>>      if (TREE_PURPOSE (t) && DECL_P (TREE_VALUE (t)))
>>>>        pedwarn (DECL_SOURCE_LOCATION (TREE_VALUE (t)), OPT_Wpedantic,
>>>>             "default argument specified for lambda parameter");
>>>>
>>>>
>>>>I didn't notice that one initially. That should also use
>>>>warn_about_dialect_p and OPT_Wc__14_extensions.
>>>
>>>Indeed.
>>>
>>>>Should I change the message to say "init capture" rather than
>>>>"default argument"?
>>>
>>>No, this is about e.g. [](int = 42){}
>>
>>OK, this is a simpler version of the patch, with docs now, but without
>>the new warn_about_cxx_dialect_p function (which isn't needed) and
>>with no changes to any actual warning text (I'll do that separately,
>>if at all).
>>
>>I also caught a few more pedwarn cases that I missed previously.
>>
>>Tested powerpc64le-linux. OK for trunk?
>
>OK.  Do we also want, say, -Wno-std-extensions to turn them all off at once?

That seems to make sense, but on the other hand Clang seems to manage
without. I wonder how useful it would be in practice. I expect that
people will usually only be using features from one standard newer
than they compile with, e.g. maybe using variadic templates in C++03,
or generic lambdas in C++11. I doubt many people are using C++20
features while compiling with -std=gnu++11, so I'm not sure how often
anybody would need to specify multiple -Wno-c++NN-extensions options.

And if they are using C++20 features with -std=gnu++11, maybe we
shouldn't be encouraging that by making it easier :-)



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-19 22:52             ` Jonathan Wakely
@ 2021-05-20 20:05               ` Jonathan Wakely
  2021-05-21 16:10                 ` Jason Merrill
  0 siblings, 1 reply; 31+ messages in thread
From: Jonathan Wakely @ 2021-05-20 20:05 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1222 bytes --]

On 19/05/21 23:52 +0100, Jonathan Wakely wrote:
>On 19/05/21 16:08 -0400, Jason Merrill wrote:
>>On 5/19/21 4:05 PM, Jonathan Wakely wrote:
>>>Oh, also we have https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93769
>>>which points out a problem with the current wording. Not a very
>>>important one, but still ...
>>>
>>>While I'm touching all 38(?) places that say "only available with
>>>-std=c++NN or -std=gnu++NN I could change them to say something like
>>>"only available since C++NN". Should I bother?
>>>
>>>Clang's equivalent warnings say "are a C++11 feature" e.g.
>>>
>>>ext.C:1:17: warning: inline namespaces are a C++11 feature 
>>>[-Wc++11-inline-namespace]
>>>
>>>(They have a specific warning for each feature, with
>>>-Wc++11-extensions to control them all at once.)
>>
>>The clang wording seems more accurate, as that PR points out.
>
>OK, that requires touching a number of error_at and inform calls as
>well as the pedwarns, so I'll address that separately in a later
>patch.

Here's a WIP patch that rewords all those diagnostics. This doesn't
include the necessary testsuite changes, and I don't know when I'll
have time to do the rest of it. But it's a start. Does this look like
the right approach?




[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 29315 bytes --]

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 7c32f09cf0e..b073883ad14 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -11166,8 +11166,8 @@ mark_inline_variable (tree decl, location_t loc)
       inlinep = false;
     }
   else if (cxx_dialect < cxx17)
-    pedwarn (loc, OPT_Wc__17_extensions, "inline variables are only available "
-	     "with %<-std=c++17%> or %<-std=gnu++17%>");
+    pedwarn (loc, OPT_Wc__17_extensions,
+	     "inline variables are a C++17 feature");
   if (inlinep)
     {
       retrofit_lang_decl (decl);
@@ -12006,9 +12006,9 @@ grokdeclarator (const cp_declarator *declarator,
 	{
 	  gcc_rich_location richloc (declspecs->locations[ds_virtual]);
 	  richloc.add_range (declspecs->locations[ds_constexpr]);
-	  pedwarn (&richloc, OPT_Wc__20_extensions, "member %qD can be "
-		   "declared both %<virtual%> and %<constexpr%> only in "
-		   "%<-std=c++20%> or %<-std=gnu++20%>", dname);
+	  pedwarn (&richloc, OPT_Wc__20_extensions, "declaring member %qD as "
+		   "both %<virtual%> and %<constexpr%> is a C++20 feature",
+		   dname);
 	}
     }
   friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
@@ -12097,8 +12097,8 @@ grokdeclarator (const cp_declarator *declarator,
 		  "binding declaration cannot be %qs", "consteval");
       if (thread_p && cxx_dialect < cxx20)
 	pedwarn (declspecs->locations[ds_thread], OPT_Wc__20_extensions,
-		 "structured binding declaration can be %qs only in "
-		 "%<-std=c++20%> or %<-std=gnu++20%>",
+		 "structured binding declarations using %qs are a C++20 "
+		 "feature",
 		 declspecs->gnu_thread_keyword_p
 		 ? "__thread" : "thread_local");
       if (concept_p)
@@ -12119,8 +12119,9 @@ grokdeclarator (const cp_declarator *declarator,
 	case sc_static:
 	  if (cxx_dialect < cxx20)
 	    pedwarn (loc, OPT_Wc__20_extensions,
-		     "structured binding declaration can be %qs only in "
-		     "%<-std=c++20%> or %<-std=gnu++20%>", "static");
+		     "structured binding declarations using %qs are a C++20 "
+		     "feature",
+		     "static");
 	  break;
 	case sc_extern:
 	  error_at (loc, "structured binding declaration cannot be %qs",
@@ -12416,8 +12417,7 @@ grokdeclarator (const cp_declarator *declarator,
 				  "%<auto%> type specifier without "
 				  "trailing return type", name);
 			inform (typespec_loc,
-				"deduced return type only available "
-				"with %<-std=c++14%> or %<-std=gnu++14%>");
+				"deduced return type is a C++14 feature");
 		      }
 		    else if (virtualp)
 		      {
@@ -12489,8 +12489,7 @@ grokdeclarator (const cp_declarator *declarator,
 		  /* Not using maybe_warn_cpp0x because this should
 		     always be an error.  */
 		  error_at (typespec_loc,
-			    "trailing return type only available "
-			    "with %<-std=c++11%> or %<-std=gnu++11%>");
+			    "trailing return type is a C++11 feature");
 		else
 		  error_at (typespec_loc, "%qs function with trailing "
 			    "return type not declared with %<auto%> "
@@ -13584,8 +13583,7 @@ grokdeclarator (const cp_declarator *declarator,
 		if (constexpr_p && cxx_dialect < cxx20)
 		  {
 		    error_at (declspecs->locations[ds_constexpr],
-			      "%<constexpr%> destructors only available"
-			      " with %<-std=c++20%> or %<-std=gnu++20%>");
+			      "%<constexpr%> destructors are a C++20 feature");
 		    return error_mark_node;
 		  }
 		if (consteval_p)
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 3d5eebd4bcd..4c7cb1725c7 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -4408,79 +4408,64 @@ maybe_warn_cpp0x (cpp0x_warn_str str)
       {
       case CPP0X_INITIALIZER_LISTS:
 	pedwarn (input_location, OPT_Wc__11_extensions,
-		 "extended initializer lists "
-		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
+		 "extended initializer lists are a C++11 feature");
 	break;
       case CPP0X_EXPLICIT_CONVERSION:
 	pedwarn (input_location, OPT_Wc__11_extensions,
-		 "explicit conversion operators "
-		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
+		 "explicit conversion operators are a C++11 feature");
 	break;
       case CPP0X_VARIADIC_TEMPLATES:
 	pedwarn (input_location, OPT_Wc__11_extensions,
-		 "variadic templates "
-		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
+		 "variadic templates are a C++11 feature");
 	break;
       case CPP0X_LAMBDA_EXPR:
 	pedwarn (input_location, OPT_Wc__11_extensions,
-		 "lambda expressions "
-		  "only available with %<-std=c++11%> or %<-std=gnu++11%>");
+		 "lambda expressions are a C++11 feature");
 	break;
       case CPP0X_AUTO:
 	pedwarn (input_location, OPT_Wc__11_extensions,
-		 "C++11 auto only available with %<-std=c++11%> or "
-		 "%<-std=gnu++11%>");
+		 "deducing types with %<auto%> is a C++11 feature");
 	break;
       case CPP0X_SCOPED_ENUMS:
 	pedwarn (input_location, OPT_Wc__11_extensions,
-		 "scoped enums only available with %<-std=c++11%> or "
-		 "%<-std=gnu++11%>");
+		 "scoped enums are a C++11 feature");
 	break;
       case CPP0X_DEFAULTED_DELETED:
 	pedwarn (input_location, OPT_Wc__11_extensions,
-		 "defaulted and deleted functions "
-		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
+		 "defaulted and deleted functions are a C++11 feature");
 	break;
       case CPP0X_INLINE_NAMESPACES:
 	if (pedantic)
 	  pedwarn (input_location, OPT_Wc__11_extensions,
-		   "inline namespaces "
-		   "only available with %<-std=c++11%> or %<-std=gnu++11%>");
+		   "inline namespaces are a C++11 feature");
 	break;
       case CPP0X_OVERRIDE_CONTROLS:
 	pedwarn (input_location, OPT_Wc__11_extensions,
-		 "override controls (override/final) "
-		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
+		 "override controls (override/final) are a C++11 feature");
         break;
       case CPP0X_NSDMI:
 	pedwarn (input_location, OPT_Wc__11_extensions,
-		 "non-static data member initializers "
-		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
+		 "non-static data member initializers are a C++11 feature");
         break;
       case CPP0X_USER_DEFINED_LITERALS:
 	pedwarn (input_location, OPT_Wc__11_extensions,
-		 "user-defined literals "
-		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
+		 "user-defined literals are a C++11 feature");
 	break;
       case CPP0X_DELEGATING_CTORS:
 	pedwarn (input_location, OPT_Wc__11_extensions,
-		 "delegating constructors "
-		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
+		 "delegating constructors are a C++11 feature");
         break;
       case CPP0X_INHERITING_CTORS:
 	pedwarn (input_location, OPT_Wc__11_extensions,
-		 "inheriting constructors "
-		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
+		 "inheriting constructors are a C++11 feature");
         break;
       case CPP0X_ATTRIBUTES:
 	pedwarn (input_location, OPT_Wc__11_extensions,
-		 "C++11 attributes "
-		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
+		 "C++-style attributes are a C++11 feature");
 	break;
       case CPP0X_REF_QUALIFIER:
 	pedwarn (input_location, OPT_Wc__11_extensions,
-		 "ref-qualifiers "
-		 "only available with %<-std=c++11%> or %<-std=gnu++11%>");
+		 "ref-qualifiers are a C++11 feature");
 	break;
       default:
 	gcc_unreachable ();
diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index dd745237f22..321869b13db 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -1165,8 +1165,7 @@ early_check_defaulted_comparison (tree fn)
 
   if (cxx_dialect < cxx20)
     {
-      error_at (loc, "defaulted %qD only available with %<-std=c++20%> or "
-		     "%<-std=gnu++20%>", fn);
+      error_at (loc, "defaulted %qD is a C++20 feature", fn);
       return false;
     }
 
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index a6c9e68a19e..d291cf0fb86 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -5626,8 +5626,7 @@ lookup_using_decl (tree scope, name_lookup &lookup)
     {
       /* Naming an enumeration member.  */
       if (cxx_dialect < cxx20)
-	error ("%<using%> with enumeration scope %q#T "
-	       "only available with %<-std=c++20%> or %<-std=gnu++20%>",
+	error ("%<using%> with enumeration scope %q#T is a C++20 feature",
 	       scope);
       lookup.value = lookup_enumerator (scope, lookup.name);
     }
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 48b83d67b34..8c8c5496866 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -3429,8 +3429,8 @@ cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree id,
 		"invalid use of template-name %qE without an argument list",
 		decl);
       if (DECL_CLASS_TEMPLATE_P (decl) && cxx_dialect < cxx17)
-	inform (location, "class template argument deduction is only available "
-		"with %<-std=c++17%> or %<-std=gnu++17%>");
+	inform (location, "class template argument deduction is a C++17 "
+			  "feature");
       inform (DECL_SOURCE_LOCATION (decl), "%qD declared here", decl);
     }
   else if (TREE_CODE (id) == BIT_NOT_EXPR)
@@ -3463,11 +3463,9 @@ cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree id,
 
 	 The user should have said "typename A<T>::X".  */
       if (cxx_dialect < cxx11 && id == ridpointers[(int)RID_CONSTEXPR])
-	inform (location, "C++11 %<constexpr%> only available with "
-		"%<-std=c++11%> or %<-std=gnu++11%>");
+	inform (location, "%<constexpr%> is a C++11 feature");
       else if (cxx_dialect < cxx11 && id == ridpointers[(int)RID_NOEXCEPT])
-	inform (location, "C++11 %<noexcept%> only available with "
-		"%<-std=c++11%> or %<-std=gnu++11%>");
+	inform (location, "%<noexcept%> is a C++11 feature");
       else if (TREE_CODE (id) == IDENTIFIER_NODE
 	       && (id_equal (id, "module") || id_equal (id, "import")))
 	{
@@ -3484,17 +3482,15 @@ cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree id,
       else if (cxx_dialect < cxx11
 	       && TREE_CODE (id) == IDENTIFIER_NODE
 	       && id_equal (id, "thread_local"))
-	inform (location, "C++11 %<thread_local%> only available with "
-		"%<-std=c++11%> or %<-std=gnu++11%>");
+	inform (location, "%<thread_local%> is a C++11 feature");
       else if (cxx_dialect < cxx20 && id == ridpointers[(int)RID_CONSTINIT])
-	inform (location, "C++20 %<constinit%> only available with "
-		"%<-std=c++20%> or %<-std=gnu++20%>");
+	inform (location, "%<constinit%> is a C++20 feature");
       else if (!flag_concepts && id == ridpointers[(int)RID_CONCEPT])
-	inform (location, "%<concept%> only available with %<-std=c++20%> or "
-		"%<-fconcepts%>");
+	inform (location, "%<concept%> is a C++20 feature, or is available "
+		"with %<-fconcepts%>");
       else if (!flag_concepts && id == ridpointers[(int)RID_REQUIRES])
-	inform (location, "%<requires%> only available with %<-std=c++20%> or "
-		"%<-fconcepts%>");
+	inform (location, "%<requires%> is a C++20 feature, or is available "
+		"with %<-fconcepts%>");
       else if (processing_template_decl && current_class_type
 	       && TYPE_BINFO (current_class_type))
 	{
@@ -5578,8 +5574,7 @@ cp_parser_primary_expression (cp_parser *parser,
 	    if (expr != error_mark_node
 		&& cxx_dialect < cxx17)
 	      pedwarn (input_location, OPT_Wc__17_extensions,
-		       "fold-expressions only available with %<-std=c++17%> "
-		       "or %<-std=gnu++17%>");
+		       "fold-expressions are a C++17 feature");
 	  }
 	else
 	  /* Let the front end know that this expression was
@@ -6327,8 +6322,7 @@ cp_parser_unqualified_id (cp_parser* parser,
 	  {
 	    if (cxx_dialect < cxx14)
 	      pedwarn (loc, OPT_Wc__14_extensions,
-		       "%<~auto%> only available with "
-		       "%<-std=c++14%> or %<-std=gnu++14%>");
+		       "%<~auto%> is a C++14 feature");
 	    cp_lexer_consume_token (parser->lexer);
 	    return build_min_nt_loc (loc, BIT_NOT_EXPR, make_auto ());
 	  }
@@ -8355,8 +8349,7 @@ cp_parser_pseudo_destructor_name (cp_parser* parser,
     {
       if (cxx_dialect < cxx14)
 	pedwarn (input_location, OPT_Wc__14_extensions,
-		 "%<~auto%> only available with "
-		 "%<-std=c++14%> or %<-std=gnu++14%>");
+		 "%<~auto%> is a C++14 feature");
       cp_lexer_consume_token (parser->lexer);
       cp_lexer_consume_token (parser->lexer);
       *scope = NULL_TREE;
@@ -10824,8 +10817,8 @@ cp_parser_lambda_expression (cp_parser* parser)
       if (!token->error_reported)
 	{
 	  error_at (LAMBDA_EXPR_LOCATION (lambda_expr),
-		    "lambda-expression in unevaluated context"
-		    " only available with %<-std=c++20%> or %<-std=gnu++20%>");
+		    "lambda-expression in unevaluated context are a "
+		    "C++20 feature");
 	  token->error_reported = true;
 	}
       ok = false;
@@ -10835,7 +10828,7 @@ cp_parser_lambda_expression (cp_parser* parser)
       if (!token->error_reported)
 	{
 	  error_at (token->location, "lambda-expression in template-argument"
-		    " only available with %<-std=c++20%> or %<-std=gnu++20%>");
+		    " is a C++20 feature");
 	  token->error_reported = true;
 	}
       ok = false;
@@ -11044,8 +11037,7 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
 	  location_t loc = cp_lexer_peek_token (parser->lexer)->location;
 	  if (cxx_dialect < cxx17)
 	    pedwarn (loc, OPT_Wc__17_extensions,
-		     "%<*this%> capture only available with "
-		     "%<-std=c++17%> or %<-std=gnu++17%>");
+		     "%<*this%> capture is a C++17 feature");
 	  cp_lexer_consume_token (parser->lexer);
 	  cp_lexer_consume_token (parser->lexer);
 	  if (LAMBDA_EXPR_THIS_CAPTURE (lambda_expr))
@@ -11084,8 +11076,7 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
 	  ellipsis_loc = cp_lexer_peek_token (parser->lexer)->location;
 	  if (cxx_dialect < cxx20)
 	    pedwarn (ellipsis_loc, OPT_Wc__20_extensions,
-		     "pack init-capture only available with "
-		     "%<-std=c++20%> or %<-std=gnu++20%>");
+		     "pack init-capture is a C++20 feature");
 	  cp_lexer_consume_token (parser->lexer);
 	  init_pack_expansion = true;
 	}
@@ -11126,8 +11117,7 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr)
 	  /* An explicit initializer exists.  */
 	  if (cxx_dialect < cxx14)
 	    pedwarn (input_location, OPT_Wc__14_extensions,
-		     "lambda capture initializers "
-		     "only available with %<-std=c++14%> or %<-std=gnu++14%>");
+		     "lambda capture initializers are a C++14 feature");
 	  capture_init_expr = cp_parser_initializer (parser, &direct,
 						     &non_constant, true);
 	  explicit_init_p = true;
@@ -11300,12 +11290,10 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
     {
       if (cxx_dialect < cxx14)
 	pedwarn (parser->lexer->next_token->location, OPT_Wc__14_extensions,
-		 "lambda templates are only available with "
-		 "%<-std=c++14%> or %<-std=gnu++14%>");
+		 "lambda templates are a C++14 feature");
       else if (pedantic && cxx_dialect < cxx20)
 	pedwarn (parser->lexer->next_token->location, OPT_Wc__20_extensions,
-		 "lambda templates are only available with "
-		 "%<-std=c++20%> or %<-std=gnu++20%>");
+		 "lambda templates are a C++20 feature");
 
       cp_lexer_consume_token (parser->lexer);
 
@@ -11394,8 +11382,7 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
     {
       pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
 	       "parameter declaration before lambda declaration "
-	       "specifiers only optional with %<-std=c++2b%> or "
-	       "%<-std=gnu++2b%>");
+	       "specifiers only optional since C++23");
       omitted_parms_loc = UNKNOWN_LOCATION;
     }
 
@@ -11413,8 +11400,7 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
     {
       pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
 	       "parameter declaration before lambda transaction "
-	       "qualifier only optional with %<-std=c++2b%> or "
-	       "%<-std=gnu++2b%>");
+	       "qualifier only optional since C++23");
       omitted_parms_loc = UNKNOWN_LOCATION;
     }
 
@@ -11426,8 +11412,7 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
     {
       pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
 	       "parameter declaration before lambda exception "
-	       "specification only optional with %<-std=c++2b%> or "
-	       "%<-std=gnu++2b%>");
+	       "specification only optional since C++23");
       omitted_parms_loc = UNKNOWN_LOCATION;
     }
 
@@ -11444,8 +11429,7 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
       if (omitted_parms_loc)
 	pedwarn (omitted_parms_loc, OPT_Wc__23_extensions,
 		 "parameter declaration before lambda trailing "
-		 "return type only optional with %<-std=c++2b%> or "
-		 "%<-std=gnu++2b%>");
+		 "return type only optional since C++23%>");
       cp_lexer_consume_token (parser->lexer);
       return_type = cp_parser_trailing_type_id (parser);
     }
@@ -11486,8 +11470,7 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
 	    = lambda_specs.locations[ds_constexpr];
 	else
 	  error_at (lambda_specs.locations[ds_constexpr], "%<constexpr%> "
-		    "lambda only available with %<-std=c++17%> or "
-		    "%<-std=gnu++17%>");
+		    "lambda is a C++17 feature");
       }
     if (lambda_specs.locations[ds_consteval])
       return_type_specs.locations[ds_consteval]
@@ -12306,8 +12289,7 @@ cp_parser_selection_statement (cp_parser* parser, bool *if_p,
 	    cp_token *tok = cp_lexer_consume_token (parser->lexer);
 	    if (cxx_dialect < cxx17)
 	      pedwarn (tok->location, OPT_Wc__17_extensions,
-		       "%<if constexpr%> only available with "
-		       "%<-std=c++17%> or %<-std=gnu++17%>");
+		       "%<if constexpr%> is a C++17 feature");
 	  }
 
 	/* Look for the `('.  */
@@ -12334,8 +12316,8 @@ cp_parser_selection_statement (cp_parser* parser, bool *if_p,
 	    if (cxx_dialect < cxx17)
 	      pedwarn (cp_lexer_peek_token (parser->lexer)->location,
 		       OPT_Wc__17_extensions,
-		       "init-statement in selection statements only available "
-		       "with %<-std=c++17%> or %<-std=gnu++17%>");
+		       "init-statement in selection statements is a C++17 "
+		       "feature");
 	    if (cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON))
 	      /* A non-empty init-statement can have arbitrary side
 		 effects.  */
@@ -13406,8 +13388,8 @@ cp_parser_init_statement (cp_parser *parser, tree *decl)
 	    {
 	      pedwarn (cp_lexer_peek_token (parser->lexer)->location,
 		       OPT_Wc__20_extensions,
-		       "range-based %<for%> loops with initializer only "
-		       "available with %<-std=c++20%> or %<-std=gnu++20%>");
+		       "range-based %<for%> loops with initializer are a "
+		       "C++20 feature")
 	      *decl = error_mark_node;
 	    }
 	}
@@ -13431,8 +13413,7 @@ cp_parser_init_statement (cp_parser *parser, tree *decl)
 	  if (cxx_dialect < cxx11)
 	    pedwarn (cp_lexer_peek_token (parser->lexer)->location,
 		     OPT_Wc__11_extensions,
-		     "range-based %<for%> loops only available with "
-		     "%<-std=c++11%> or %<-std=gnu++11%>");
+		     "range-based %<for%> loops are a C++11 feature");
 	}
       else
 	/* The ';' is not consumed yet because we told
@@ -14674,8 +14655,7 @@ cp_parser_decomposition_declaration (cp_parser *parser,
 
   if (cxx_dialect < cxx17)
     pedwarn (loc, OPT_Wc__17_extensions,
-	     "structured bindings only available with "
-	     "%<-std=c++17%> or %<-std=gnu++17%>");
+	     "structured bindings are a C++17 feature");
 
   tree pushed_scope;
   cp_declarator *declarator = make_declarator (cdk_decomp);
@@ -15271,8 +15251,7 @@ cp_parser_function_specifier_opt (cp_parser* parser,
 
 	    if (cxx_dialect < cxx20)
 	      pedwarn (token->location, OPT_Wc__20_extensions,
-		       "%<explicit(bool)%> only available with %<-std=c++20%> "
-		       "or %<-std=gnu++20%>");
+		       "%<explicit(bool)%> is a C++20 feature");
 
 	    /* Parse the constant-expression.  */
 	    expr = cp_parser_constant_expression (parser);
@@ -15439,8 +15418,7 @@ cp_parser_static_assert(cp_parser *parser, bool member_p)
     {
       if (pedantic && cxx_dialect < cxx17)
 	pedwarn (input_location, OPT_Wc__17_extensions,
-		 "%<static_assert%> without a message "
-		 "only available with %<-std=c++17%> or %<-std=gnu++17%>");
+		 "%<static_assert%> without a message is a C++17 feature");
       /* Eat the ')'  */
       cp_lexer_consume_token (parser->lexer);
       message = build_string (1, "");
@@ -15641,8 +15619,7 @@ cp_parser_decltype (cp_parser *parser)
       if (cxx_dialect < cxx14)
 	{
 	  error_at (start_token->location,
-		    "%<decltype(auto)%> type specifier only available with "
-		    "%<-std=c++14%> or %<-std=gnu++14%>");
+		    "%<decltype(auto)%> type specifier is a C++14 feature");
 	  expr = error_mark_node;
 	}
     }
@@ -18770,14 +18747,12 @@ cp_parser_simple_type_specifier (cp_parser* parser,
 	      if (cxx_dialect < cxx14)
 		error_at (token->location,
 			 "use of %<auto%> in lambda parameter declaration "
-			 "only available with "
-			 "%<-std=c++14%> or %<-std=gnu++14%>");
+			 "is a C++14 feature");
 	    }
 	  else if (cxx_dialect < cxx14)
 	    error_at (token->location,
 		     "use of %<auto%> in parameter declaration "
-		     "only available with "
-		     "%<-std=c++14%> or %<-std=gnu++14%>");
+		     "is a C++14 feature");
 	  else if (!flag_concepts)
 	    pedwarn (token->location, 0,
 		     "use of %<auto%> in parameter declaration "
@@ -20430,8 +20405,7 @@ cp_parser_namespace_definition (cp_parser* parser)
 	  if (pedantic && cxx_dialect < cxx20)
 	    pedwarn (cp_lexer_peek_token (parser->lexer)->location,
 		     OPT_Wc__20_extensions, "nested inline namespace "
-		     "definitions only available with %<-std=c++20%> or "
-		     "%<-std=gnu++20%>");
+		     "definitions are a C++20 feature");
 	  cp_lexer_consume_token (parser->lexer);
 	}
 
@@ -20460,8 +20434,7 @@ cp_parser_namespace_definition (cp_parser* parser)
 
       if (!nested_definition_count && pedantic && cxx_dialect < cxx17)
         pedwarn (input_location, OPT_Wc__17_extensions,
-		 "nested namespace definitions only available with "
-		 "%<-std=c++17%> or %<-std=gnu++17%>");
+		 "nested namespace definitions are a C++17 feature");
 
       /* Nested namespace names can create new namespaces (unlike
 	 other qualified-ids).  */
@@ -20719,8 +20692,7 @@ cp_parser_using_declaration (cp_parser* parser,
       cp_token *ell = cp_lexer_consume_token (parser->lexer);
       if (cxx_dialect < cxx17)
 	pedwarn (ell->location, OPT_Wc__17_extensions,
-		 "pack expansion in using-declaration only available "
-		 "with %<-std=c++17%> or %<-std=gnu++17%>");
+		 "pack expansion in using-declaration is a C++17 feature");
       qscope = make_pack_expansion (qscope);
     }
 
@@ -20752,8 +20724,8 @@ cp_parser_using_declaration (cp_parser* parser,
       cp_token *comma = cp_lexer_consume_token (parser->lexer);
       if (cxx_dialect < cxx17)
 	pedwarn (comma->location, OPT_Wc__17_extensions,
-		 "comma-separated list in using-declaration only available "
-		 "with %<-std=c++17%> or %<-std=gnu++17%>");
+		 "comma-separated list in using-declaration is a C++17 "
+		 "feature");
       goto again;
     }
 
@@ -20808,8 +20780,7 @@ cp_parser_using_enum (cp_parser *parser)
      shall have a reachable enum-specifier.  */
   const char *msg = nullptr;
   if (cxx_dialect < cxx20)
-    msg = _("%<using enum%> "
-	    "only available with %<-std=c++20%> or %<-std=gnu++20%>");
+    msg = _("%<using enum%> is a C++20 feature");
   else if (dependent_type_p (type))
     msg = _("%<using enum%> of dependent type %qT");
   else if (TREE_CODE (type) != ENUMERAL_TYPE)
@@ -21069,8 +21040,7 @@ cp_parser_asm_definition (cp_parser* parser)
       && DECL_DECLARED_CONSTEXPR_P (current_function_decl)
       && cxx_dialect < cxx20)
     pedwarn (asm_loc, OPT_Wc__20_extensions, "%<asm%> in %<constexpr%> "
-	     "function only available with %<-std=c++20%> or "
-	     "%<-std=gnu++20%>");
+	     "function is a C++20 feature");
 
   /* Handle the asm-qualifier-list.  */
   location_t volatile_loc = UNKNOWN_LOCATION;
@@ -24143,12 +24113,12 @@ cp_parser_ctor_initializer_opt_and_function_body (cp_parser *parser,
     {
       if (DECL_CONSTRUCTOR_P (current_function_decl))
 	pedwarn (input_location, OPT_Wc__20_extensions,
-		 "function-try-block body of %<constexpr%> constructor only "
-		 "available with %<-std=c++20%> or %<-std=gnu++20%>");
+		 "function-try-block body of %<constexpr%> constructor "
+		 "is a C++20 feature");
       else
 	pedwarn (input_location, OPT_Wc__20_extensions,
-		 "function-try-block body of %<constexpr%> function only "
-		 "available with %<-std=c++20%> or %<-std=gnu++20%>");
+		 "function-try-block body of %<constexpr%> function "
+		 "is a C++20 feature");
     }
 
   /* Begin the function body.  */
@@ -24471,8 +24441,7 @@ cp_parser_initializer_list (cp_parser* parser, bool* non_constant_p,
 	{
 	  if (pedantic && cxx_dialect < cxx20)
 	    pedwarn (loc, OPT_Wc__20_extensions,
-		     "C++ designated initializers only available with "
-		     "%<-std=c++20%> or %<-std=gnu++20%>");
+		     "C++ designated initializers are a C++20 feature");
 	  /* Consume the `.'.  */
 	  cp_lexer_consume_token (parser->lexer);
 	  /* Consume the identifier.  */
@@ -25816,8 +25785,8 @@ cp_parser_type_parameter_key (cp_parser* parser)
 	/* typename is not allowed in a template template parameter
 	   by the standard until C++17.  */
 	pedwarn (token->location, OPT_Wc__17_extensions,
-		 "ISO C++ forbids typename key in template template parameter;"
-		 " use %<-std=c++17%> or %<-std=gnu++17%>");
+		 "typename key in template template parameter is a C++17 "
+		 "feature");
     }
   else
     cp_parser_error (parser, "expected %<class%> or %<typename%>");
@@ -26211,8 +26180,7 @@ cp_parser_member_declaration (cp_parser* parser)
 		      && identifier != NULL_TREE)
 		    pedwarn (loc, OPT_Wc__20_extensions,
 			     "default member initializers for bit-fields "
-			     "only available with %<-std=c++20%> or "
-			     "%<-std=gnu++20%>");
+			     "are a C++20 feature");
 
 		  initializer = cp_parser_save_nsdmi (parser);
 		  if (identifier == NULL_TREE)
@@ -27171,8 +27139,7 @@ cp_parser_try_block (cp_parser* parser)
       && DECL_DECLARED_CONSTEXPR_P (current_function_decl)
       && cxx_dialect < cxx20)
     pedwarn (input_location, OPT_Wc__20_extensions,
-	     "%<try%> in %<constexpr%> function only "
-	     "available with %<-std=c++20%> or %<-std=gnu++20%>");
+	     "%<try%> in %<constexpr%> function is a C++20 feature");
 
   try_block = begin_try_block ();
   cp_parser_compound_statement (parser, NULL, BCS_TRY_BLOCK, false);
@@ -28130,8 +28097,7 @@ cp_parser_std_attribute_spec (cp_parser *parser)
 	    {
 	      if (cxx_dialect < cxx17)
 		pedwarn (input_location, OPT_Wc__17_extensions,
-			 "attribute using prefix only available "
-			 "with %<-std=c++17%> or %<-std=gnu++17%>");
+			 "attribute using prefix is a C++17 feature");
 
 	      cp_lexer_consume_token (parser->lexer);
 	      cp_lexer_consume_token (parser->lexer);
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 3d1787b6fc3..43a76a9aece 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -2704,8 +2704,7 @@ check_template_variable (tree decl)
     {
       if (cxx_dialect < cxx14)
         pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wc__14_extensions,
-		 "variable templates only available with "
-		 "%<-std=c++14%> or %<-std=gnu++14%>");
+		 "variable templates are a C++14 feature");
 
       // Namespace-scope variable templates should have a template header.
       ++wanted;
@@ -5583,8 +5582,8 @@ check_default_tmpl_args (tree decl, tree parms, bool is_primary,
     msg = G_("default template arguments may not be used in template "
 	     "friend declarations");
   else if (TREE_CODE (decl) == FUNCTION_DECL && (cxx_dialect == cxx98))
-    msg = G_("default template arguments may not be used in function templates "
-	     "without %<-std=c++11%> or %<-std=gnu++11%>");
+    msg = G_("default template arguments in function templates "
+	     "are a C++11 feature");
   else if (is_partial)
     msg = G_("default template arguments may not be used in "
 	     "partial specializations");
@@ -26546,8 +26545,8 @@ invalid_nontype_parm_type_p (tree type, tsubst_flags_t complain)
       if (CLASS_PLACEHOLDER_TEMPLATE (type) && cxx_dialect < cxx20)
 	{
 	  if (complain & tf_error)
-	    error ("non-type template parameters of deduced class type only "
-		   "available with %<-std=c++20%> or %<-std=gnu++20%>");
+	    error ("non-type template parameters of deduced class type "
+		   "are a C++20 feature");
 	  return true;
 	}
       return false;
@@ -26587,8 +26586,8 @@ invalid_nontype_parm_type_p (tree type, tsubst_flags_t complain)
   else if (CLASS_TYPE_P (type))
     {
       if (complain & tf_error)
-	error ("non-type template parameters of class type only available "
-	       "with %<-std=c++20%> or %<-std=gnu++20%>");
+	error ("non-type template parameters of class type are a C++20 "
+	       "feature");
       return true;
     }
 
@@ -29304,8 +29303,7 @@ do_class_deduction (tree ptype, tree tmpl, tree init,
   else if (cxx_dialect < cxx20 && DECL_ALIAS_TEMPLATE_P (tmpl))
     {
       if (complain & tf_error)
-	error ("alias template deduction only available "
-	       "with %<-std=c++20%> or %<-std=gnu++20%>");
+	error ("alias template deduction is a C++20 feature");
       return error_mark_node;
     }
 

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] c++: Add new warning options for C++ language mismatches
  2021-05-20 20:05               ` Jonathan Wakely
@ 2021-05-21 16:10                 ` Jason Merrill
  0 siblings, 0 replies; 31+ messages in thread
From: Jason Merrill @ 2021-05-21 16:10 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-patches

On 5/20/21 4:05 PM, Jonathan Wakely wrote:
> On 19/05/21 23:52 +0100, Jonathan Wakely wrote:
>> On 19/05/21 16:08 -0400, Jason Merrill wrote:
>>> On 5/19/21 4:05 PM, Jonathan Wakely wrote:
>>>> Oh, also we have https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93769
>>>> which points out a problem with the current wording. Not a very
>>>> important one, but still ...
>>>>
>>>> While I'm touching all 38(?) places that say "only available with
>>>> -std=c++NN or -std=gnu++NN I could change them to say something like
>>>> "only available since C++NN". Should I bother?
>>>>
>>>> Clang's equivalent warnings say "are a C++11 feature" e.g.
>>>>
>>>> ext.C:1:17: warning: inline namespaces are a C++11 feature 
>>>> [-Wc++11-inline-namespace]
>>>>
>>>> (They have a specific warning for each feature, with
>>>> -Wc++11-extensions to control them all at once.)
>>>
>>> The clang wording seems more accurate, as that PR points out.
>>
>> OK, that requires touching a number of error_at and inform calls as
>> well as the pedwarns, so I'll address that separately in a later
>> patch.
> 
> Here's a WIP patch that rewords all those diagnostics. This doesn't
> include the necessary testsuite changes, and I don't know when I'll
> have time to do the rest of it. But it's a start. Does this look like
> the right approach?

> +			    "trailing return type is a C++11 feature");
...
> +			      "%<constexpr%> destructors are a C++20 feature");

I wonder if we want to standardize on singular or plural.

I wonder if we want to keep the mention of the -std= option, possibly 
also mentioning the currently active standard level.

Jason


^ permalink raw reply	[flat|nested] 31+ messages in thread

* options, '-Wc++[...]-extensions': Remove undefined one-argument 'LangEnabledBy' option properties (was: [PATCH] c++: Add new warning options for C++ language mismatches)
  2021-05-19 17:09       ` Marek Polacek
@ 2022-03-29  9:27         ` Thomas Schwinge
  2022-03-29 11:34           ` Jonathan Wakely
  2022-03-29 18:13           ` Joseph Myers
  0 siblings, 2 replies; 31+ messages in thread
From: Thomas Schwinge @ 2022-03-29  9:27 UTC (permalink / raw)
  To: Marek Polacek, Jonathan Wakely, gcc-patches, Joseph Myers

[-- Attachment #1: Type: text/plain, Size: 2064 bytes --]

Hi!

On 2021-05-19T13:09:29-0400, Marek Polacek via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
> On Wed, May 19, 2021 at 05:59:34PM +0100, Jonathan Wakely wrote:
>> On 19/05/21 12:53 -0400, Marek Polacek wrote:
>> > On Wed, May 19, 2021 at 05:39:24PM +0100, Jonathan Wakely via Gcc-patches wrote:
>> > > --- a/gcc/c-family/c.opt
>> > > +++ b/gcc/c-family/c.opt

>> > > +Wc++11-extensions
>> > > +C++ ObjC++ Var(warn_cxx11_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
>> > > +Warn about C++11 constructs in code compiled with an older standard.
>> > > +
>> > > +[Etc.]

>> > So these are enabled by -Wall but also turned on by default?  Let's choose one
>> > and then drop either the Init(1) or the LangEnabledBy(C++ ObjC++,Wall) part?
>>
>> Ah, good point. I mostly just cargo-cult what I see in that file (is
>> the format documented somewhere?)
>
> doc/options.texi I think.

Correct.

>> I think to preserve the current behaviour (using these constructs in
>> an unsupported dialect warns by default) we want them to be Init(1)
>> but not in -Wall. [...]

What you pushed in commit ee336ecb2a7161bc28f6c5343d97870a8d15e177
"c++: Add new warning options for C++ language mismatches" then had the
new options defined as follows; specifying 'LangEnabledBy(C++ ObjC++)'
instead of originally-posted 'LangEnabledBy(C++ ObjC++,Wall)':

| --- gcc/c-family/c.opt
| +++ gcc/c-family/c.opt
| [...]
| +Wc++11-extensions
| +C++ ObjC++ Var(warn_cxx11_extensions) Warning LangEnabledBy(C++ ObjC++) Init(1)
| +Warn about C++11 constructs in code compiled with an older standard.
| +
| +[Etc.]

OK to push the attached "options, '-Wc++[...]-extensions':
Remove undefined one-argument 'LangEnabledBy' option properties"?


Grüße
 Thomas


-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-options-Wc-.-extensions-Remove-undefined-one-argumen.patch --]
[-- Type: text/x-diff, Size: 2359 bytes --]

From 78ee403f982526e0c026719c450dc5aead84accf Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 26 Mar 2022 22:21:14 +0100
Subject: [PATCH] options, '-Wc++[...]-extensions': Remove undefined
 one-argument 'LangEnabledBy' option properties

A one-argument form of the 'LangEnabledBy' option property isn't defined,
and effectively appears to be a no-op.  Removing these only changes
'build-gcc/gcc/optionlist' accordingly, but no other generated files.

Clean-up for commit ee336ecb2a7161bc28f6c5343d97870a8d15e177
"c++: Add new warning options for C++ language mismatches".

	gcc/c-family/
	* c.opt (Wc++11-extensions, Wc++14-extensions, Wc++17-extensions)
	(Wc++20-extensions, Wc++23-extensions): Remove 'LangEnabledBy'
	option properties.
---
 gcc/c-family/c.opt | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 1034a1b3946..07da40ef43b 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -459,23 +459,23 @@ C++ ObjC++ Var(warn_cxx20_compat) Warning LangEnabledBy(C++ ObjC++,Wall)
 Warn about C++ constructs whose meaning differs between ISO C++ 2017 and ISO C++ 2020.
 
 Wc++11-extensions
-C++ ObjC++ Var(warn_cxx11_extensions) Warning LangEnabledBy(C++ ObjC++) Init(1)
+C++ ObjC++ Var(warn_cxx11_extensions) Warning Init(1)
 Warn about C++11 constructs in code compiled with an older standard.
 
 Wc++14-extensions
-C++ ObjC++ Var(warn_cxx14_extensions) Warning LangEnabledBy(C++ ObjC++) Init(1)
+C++ ObjC++ Var(warn_cxx14_extensions) Warning Init(1)
 Warn about C++14 constructs in code compiled with an older standard.
 
 Wc++17-extensions
-C++ ObjC++ Var(warn_cxx17_extensions) Warning LangEnabledBy(C++ ObjC++) Init(1)
+C++ ObjC++ Var(warn_cxx17_extensions) Warning Init(1)
 Warn about C++17 constructs in code compiled with an older standard.
 
 Wc++20-extensions
-C++ ObjC++ Var(warn_cxx20_extensions) Warning LangEnabledBy(C++ ObjC++) Init(1)
+C++ ObjC++ Var(warn_cxx20_extensions) Warning Init(1)
 Warn about C++20 constructs in code compiled with an older standard.
 
 Wc++23-extensions
-C++ ObjC++ Var(warn_cxx23_extensions) Warning LangEnabledBy(C++ ObjC++) Init(1)
+C++ ObjC++ Var(warn_cxx23_extensions) Warning Init(1)
 Warn about C++23 constructs in code compiled with an older standard.
 
 Wcast-function-type
-- 
2.25.1


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: options, '-Wc++[...]-extensions': Remove undefined one-argument 'LangEnabledBy' option properties (was: [PATCH] c++: Add new warning options for C++ language mismatches)
  2022-03-29  9:27         ` options, '-Wc++[...]-extensions': Remove undefined one-argument 'LangEnabledBy' option properties (was: [PATCH] c++: Add new warning options for C++ language mismatches) Thomas Schwinge
@ 2022-03-29 11:34           ` Jonathan Wakely
  2022-03-29 18:13           ` Joseph Myers
  1 sibling, 0 replies; 31+ messages in thread
From: Jonathan Wakely @ 2022-03-29 11:34 UTC (permalink / raw)
  To: Thomas Schwinge; +Cc: Marek Polacek, gcc Patches, Joseph Myers

On Tue, 29 Mar 2022 at 10:28, Thomas Schwinge wrote:
>
> Hi!
>
> On 2021-05-19T13:09:29-0400, Marek Polacek via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
> > On Wed, May 19, 2021 at 05:59:34PM +0100, Jonathan Wakely wrote:
> >> On 19/05/21 12:53 -0400, Marek Polacek wrote:
> >> > On Wed, May 19, 2021 at 05:39:24PM +0100, Jonathan Wakely via Gcc-patches wrote:
> >> > > --- a/gcc/c-family/c.opt
> >> > > +++ b/gcc/c-family/c.opt
>
> >> > > +Wc++11-extensions
> >> > > +C++ ObjC++ Var(warn_cxx11_extensions) Warning LangEnabledBy(C++ ObjC++,Wall) Init(1)
> >> > > +Warn about C++11 constructs in code compiled with an older standard.
> >> > > +
> >> > > +[Etc.]
>
> >> > So these are enabled by -Wall but also turned on by default?  Let's choose one
> >> > and then drop either the Init(1) or the LangEnabledBy(C++ ObjC++,Wall) part?
> >>
> >> Ah, good point. I mostly just cargo-cult what I see in that file (is
> >> the format documented somewhere?)
> >
> > doc/options.texi I think.
>
> Correct.
>
> >> I think to preserve the current behaviour (using these constructs in
> >> an unsupported dialect warns by default) we want them to be Init(1)
> >> but not in -Wall. [...]
>
> What you pushed in commit ee336ecb2a7161bc28f6c5343d97870a8d15e177
> "c++: Add new warning options for C++ language mismatches" then had the
> new options defined as follows; specifying 'LangEnabledBy(C++ ObjC++)'
> instead of originally-posted 'LangEnabledBy(C++ ObjC++,Wall)':
>
> | --- gcc/c-family/c.opt
> | +++ gcc/c-family/c.opt
> | [...]
> | +Wc++11-extensions
> | +C++ ObjC++ Var(warn_cxx11_extensions) Warning LangEnabledBy(C++ ObjC++) Init(1)
> | +Warn about C++11 constructs in code compiled with an older standard.
> | +
> | +[Etc.]
>
> OK to push the attached "options, '-Wc++[...]-extensions':
> Remove undefined one-argument 'LangEnabledBy' option properties"?

I can't approve it, but no objections from me.


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: options, '-Wc++[...]-extensions': Remove undefined one-argument 'LangEnabledBy' option properties (was: [PATCH] c++: Add new warning options for C++ language mismatches)
  2022-03-29  9:27         ` options, '-Wc++[...]-extensions': Remove undefined one-argument 'LangEnabledBy' option properties (was: [PATCH] c++: Add new warning options for C++ language mismatches) Thomas Schwinge
  2022-03-29 11:34           ` Jonathan Wakely
@ 2022-03-29 18:13           ` Joseph Myers
  1 sibling, 0 replies; 31+ messages in thread
From: Joseph Myers @ 2022-03-29 18:13 UTC (permalink / raw)
  To: Thomas Schwinge; +Cc: Marek Polacek, Jonathan Wakely, gcc-patches

On Tue, 29 Mar 2022, Thomas Schwinge wrote:

> | --- gcc/c-family/c.opt
> | +++ gcc/c-family/c.opt
> | [...]
> | +Wc++11-extensions
> | +C++ ObjC++ Var(warn_cxx11_extensions) Warning LangEnabledBy(C++ ObjC++) Init(1)
> | +Warn about C++11 constructs in code compiled with an older standard.
> | +
> | +[Etc.]
> 
> OK to push the attached "options, '-Wc++[...]-extensions':
> Remove undefined one-argument 'LangEnabledBy' option properties"?

OK.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2022-03-29 18:54 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-19 16:32 [PATCH] c++: Add new warning options for C++ language mismatches Jonathan Wakely
2021-05-19 16:39 ` Jonathan Wakely
2021-05-19 16:46   ` Jonathan Wakely
2021-05-19 17:26     ` Jason Merrill
2021-05-19 19:55       ` Jonathan Wakely
2021-05-19 20:05         ` Jonathan Wakely
2021-05-19 20:08           ` Jason Merrill
2021-05-19 22:52             ` Jonathan Wakely
2021-05-20 20:05               ` Jonathan Wakely
2021-05-21 16:10                 ` Jason Merrill
2021-05-19 20:05         ` Jason Merrill
2021-05-20 12:56           ` Jonathan Wakely
2021-05-20 16:34             ` Jason Merrill
2021-05-20 19:49               ` Jonathan Wakely
2021-05-20 17:25             ` Martin Sebor
2021-05-20 19:32               ` Jonathan Wakely
2021-05-19 16:53   ` Marek Polacek
2021-05-19 16:59     ` Jonathan Wakely
2021-05-19 17:09       ` Marek Polacek
2022-03-29  9:27         ` options, '-Wc++[...]-extensions': Remove undefined one-argument 'LangEnabledBy' option properties (was: [PATCH] c++: Add new warning options for C++ language mismatches) Thomas Schwinge
2022-03-29 11:34           ` Jonathan Wakely
2022-03-29 18:13           ` Joseph Myers
2021-05-19 17:51   ` [PATCH] c++: Add new warning options for C++ language mismatches Martin Sebor
2021-05-19 18:03     ` Marek Polacek
2021-05-19 18:35       ` Jonathan Wakely
2021-05-19 18:41         ` Marek Polacek
2021-05-19 23:05     ` Jonathan Wakely
2021-05-19 23:12     ` Jonathan Wakely
2021-05-19 16:40 ` Eric Gallager
2021-05-19 16:50   ` Jonathan Wakely
2021-05-19 16:56     ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).