diff mbox

[C++] pedwarn issues

Message ID 53ECFF9D.4030508@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Aug. 14, 2014, 6:27 p.m. UTC
Hi,

a few cases where under SFINAE we just go ahead and we don't immediately 
return error_mark_node. During the work I also noticed a glitch in 
cxx_sizeof_or_alignof_type where we do complain & tf_warning_or_error 
but in that case complain is a bool.

Tested x86_64-linux as usual.

Thanks,
Paolo.

////////////////////
2014-08-14  Paolo Carlini  <paolo.carlini@oracle.com>

	* typeck.c (composite_pointer_type, cxx_sizeof_or_alignof_type,
	cp_build_array_ref, cp_build_function_call_vec): When a
	pedwarn is suppressed under SFINAE, return error_mark_node.

	* typeck.c (cxx_sizeof_or_alignof_type): Fix complain &
	tf_warning_or_error, where complain is a bool, glitch.

Comments

Jason Merrill Aug. 14, 2014, 7:26 p.m. UTC | #1
OK, thanks.

Jason
diff mbox

Patch

Index: typeck.c
===================================================================
--- typeck.c	(revision 213976)
+++ typeck.c	(working copy)
@@ -597,28 +597,34 @@  composite_pointer_type (tree t1, tree t2, tree arg
       tree attributes;
       tree result_type;
 
-      if (TYPE_PTRFN_P (t2) && (complain & tf_error))
-        {
-          switch (operation)
-              {
-              case CPO_COMPARISON:
-                pedwarn (input_location, OPT_Wpedantic, 
-                         "ISO C++ forbids comparison between "
-                         "pointer of type %<void *%> and pointer-to-function");
-                break;
-              case CPO_CONVERSION:
-                pedwarn (input_location, OPT_Wpedantic,
-                         "ISO C++ forbids conversion between "
-                         "pointer of type %<void *%> and pointer-to-function");
-                break;
-              case CPO_CONDITIONAL_EXPR:
-                pedwarn (input_location, OPT_Wpedantic,
-                         "ISO C++ forbids conditional expression between "
-                         "pointer of type %<void *%> and pointer-to-function");
-                break;
-              default:
-                gcc_unreachable ();
-              }
+      if (TYPE_PTRFN_P (t2))
+	{
+	  if (complain & tf_error)
+	    {
+	      switch (operation)
+		{
+		case CPO_COMPARISON:
+		  pedwarn (input_location, OPT_Wpedantic, 
+			   "ISO C++ forbids comparison between pointer "
+			   "of type %<void *%> and pointer-to-function");
+		  break;
+		case CPO_CONVERSION:
+		  pedwarn (input_location, OPT_Wpedantic,
+			   "ISO C++ forbids conversion between pointer "
+			   "of type %<void *%> and pointer-to-function");
+		  break;
+		case CPO_CONDITIONAL_EXPR:
+		  pedwarn (input_location, OPT_Wpedantic,
+			   "ISO C++ forbids conditional expression between "
+			   "pointer of type %<void *%> and "
+			   "pointer-to-function");
+		  break;
+		default:
+		  gcc_unreachable ();
+		}
+	    }
+	  else
+	    return error_mark_node;
         }
       result_type
 	= cp_build_qualified_type (void_type_node,
@@ -1536,6 +1542,8 @@  cxx_sizeof_or_alignof_type (tree type, enum tree_c
 	pedwarn (input_location, OPT_Wpointer_arith, 
 		 "invalid application of %qs to a member function", 
 		 operator_name_info[(int) op].name);
+      else
+	return error_mark_node;
       value = size_one_node;
     }
 
@@ -1561,7 +1569,7 @@  cxx_sizeof_or_alignof_type (tree type, enum tree_c
   if (cxx_dialect >= cxx1y && array_of_runtime_bound_p (type)
       && (flag_iso || warn_vla > 0))
     {
-      if (complain & tf_warning_or_error)
+      if (complain)
 	pedwarn (input_location, OPT_Wvla,
 		 "taking sizeof array of runtime bound");
       else
@@ -3129,9 +3137,14 @@  cp_build_array_ref (location_t loc, tree array, tr
 	    return error_mark_node;
 	}
 
-      if (!lvalue_p (array) && (complain & tf_error))
-	pedwarn (loc, OPT_Wpedantic, 
-	         "ISO C++ forbids subscripting non-lvalue array");
+      if (!lvalue_p (array))
+	{
+	  if (complain & tf_error)
+	    pedwarn (loc, OPT_Wpedantic, 
+		     "ISO C++ forbids subscripting non-lvalue array");
+	  else
+	    return error_mark_node;
+	}
 
       /* Note in C++ it is valid to subscript a `register' array, since
 	 it is valid to take the address of something with that
@@ -3467,10 +3480,14 @@  cp_build_function_call_vec (tree function, vec<tre
       fndecl = function;
 
       /* Convert anything with function type to a pointer-to-function.  */
-      if (DECL_MAIN_P (function) && (complain & tf_error))
-	pedwarn (input_location, OPT_Wpedantic, 
-		 "ISO C++ forbids calling %<::main%> from within program");
-
+      if (DECL_MAIN_P (function))
+	{
+	  if (complain & tf_error)
+	    pedwarn (input_location, OPT_Wpedantic, 
+		     "ISO C++ forbids calling %<::main%> from within program");
+	  else
+	    return error_mark_node;
+	}
       function = build_addr_func (function, complain);
     }
   else