diff mbox series

[C++,obvious?] Change check_static_variable_definition return type to void

Message ID be17033d-7a33-a358-fcfd-24687771f92d@oracle.com
State New
Headers show
Series [C++,obvious?] Change check_static_variable_definition return type to void | expand

Commit Message

Paolo Carlini Aug. 21, 2018, 10:20 a.m. UTC
Hi,

over the last couple of weeks I started auditing the front-end about 
problematic uses of permerror (say, the user passes -fpermissive and 
after the warning we immediately return error_mark_node anyway: the 
assembly most likely will not make sense) and noticed that we don't use 
anywhere the return value of check_static_variable_definition (luckily, 
because we are returning 1 both for error and permerror), thus the 
below, which just changes the return type to void and consistently 
adjusts the body. I mean to commit it as obvious after testing finishes...

Thanks, Paolo.

////////////////////////////
2018-08-21  Paolo Carlini  <paolo.carlini@oracle.com>

	* decl.c (check_static_variable_definition): Change to return void.

Comments

Jason Merrill Aug. 21, 2018, 11:21 a.m. UTC | #1
This doesn't seem obvious to me, since it is removing information from
the interface of the function.  But it is OK.

On Tue, Aug 21, 2018 at 10:20 PM, Paolo Carlini
<paolo.carlini@oracle.com> wrote:
> Hi,
>
> over the last couple of weeks I started auditing the front-end about
> problematic uses of permerror (say, the user passes -fpermissive and after
> the warning we immediately return error_mark_node anyway: the assembly most
> likely will not make sense) and noticed that we don't use anywhere the
> return value of check_static_variable_definition (luckily, because we are
> returning 1 both for error and permerror), thus the below, which just
> changes the return type to void and consistently adjusts the body. I mean to
> commit it as obvious after testing finishes...
>
> Thanks, Paolo.
>
> ////////////////////////////
>
diff mbox series

Patch

Index: decl.c
===================================================================
--- decl.c	(revision 263695)
+++ decl.c	(working copy)
@@ -70,7 +70,7 @@  static void push_local_name (tree);
 static tree grok_reference_init (tree, tree, tree, int);
 static tree grokvardecl (tree, tree, tree, const cp_decl_specifier_seq *,
 			 int, int, int, bool, int, tree);
-static int check_static_variable_definition (tree, tree);
+static void check_static_variable_definition (tree, tree);
 static void record_unknown_type (tree, const char *);
 static tree builtin_function_1 (tree, tree, bool);
 static int member_function_or_else (tree, tree, enum overload_flags);
@@ -9531,25 +9531,24 @@  build_ptrmem_type (tree class_type, tree member_ty
 
 /* DECL is a VAR_DECL defined in-class, whose TYPE is also given.
    Check to see that the definition is valid.  Issue appropriate error
-   messages.  Return 1 if the definition is particularly bad, or 0
-   otherwise.  */
+   messages.  */
 
-static int
+static void
 check_static_variable_definition (tree decl, tree type)
 {
   /* Avoid redundant diagnostics on out-of-class definitions.  */
   if (!current_class_type || !TYPE_BEING_DEFINED (current_class_type))
-    return 0;
+    ;
   /* Can't check yet if we don't know the type.  */
-  if (dependent_type_p (type))
-    return 0;
+  else if (dependent_type_p (type))
+    ;
   /* If DECL is declared constexpr, we'll do the appropriate checks
      in check_initializer.  Similarly for inline static data members.  */
-  if (DECL_P (decl)
+  else if (DECL_P (decl)
       && (DECL_DECLARED_CONSTEXPR_P (decl)
 	  || undeduced_auto_decl (decl)
 	  || DECL_VAR_DECLARED_INLINE_P (decl)))
-    return 0;
+    ;
   else if (cxx_dialect >= cxx11 && !INTEGRAL_OR_ENUMERATION_TYPE_P (type))
     {
       if (!COMPLETE_TYPE_P (type))
@@ -9564,9 +9563,7 @@  check_static_variable_definition (tree decl, tree
 	error_at (DECL_SOURCE_LOCATION (decl),
 		  "in-class initialization of static data member %q#D of "
 		  "non-literal type", decl);
-      return 1;
     }
-
   /* Motion 10 at San Diego: If a static const integral data member is
      initialized with an integral constant expression, the initializer
      may appear either in the declaration (within the class), or in
@@ -9573,14 +9570,11 @@  check_static_variable_definition (tree decl, tree
      the definition, but not both.  If it appears in the class, the
      member is a member constant.  The file-scope definition is always
      required.  */
-  if (!ARITHMETIC_TYPE_P (type) && TREE_CODE (type) != ENUMERAL_TYPE)
-    {
-      error_at (DECL_SOURCE_LOCATION (decl),
-		"invalid in-class initialization of static data member "
-		"of non-integral type %qT",
-		type);
-      return 1;
-    }
+  else if (!ARITHMETIC_TYPE_P (type) && TREE_CODE (type) != ENUMERAL_TYPE)
+    error_at (DECL_SOURCE_LOCATION (decl),
+	      "invalid in-class initialization of static data member "
+	      "of non-integral type %qT",
+	      type);
   else if (!CP_TYPE_CONST_P (type))
     error_at (DECL_SOURCE_LOCATION (decl),
 	      "ISO C++ forbids in-class initialization of non-const "
@@ -9590,8 +9584,6 @@  check_static_variable_definition (tree decl, tree
     pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
 	     "ISO C++ forbids initialization of member constant "
 	     "%qD of non-integral type %qT", decl, type);
-
-  return 0;
 }
 
 /* *expr_p is part of the TYPE_SIZE of a variably-sized array.  If any