diff mbox

[C++] PR 60955

Message ID 5492B7B7.8060402@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Dec. 18, 2014, 11:17 a.m. UTC
Hi,

On 12/17/2014 09:37 PM, Jason Merrill wrote:
> I'm uncomfortable with setting TREE_NO_WARNING on a decl just because 
> we don't want a warning for one particular use of it.  How about 
> suppressing warnings across the call to build_static_cast?
Sure. The below uses the c_inhibit_evaluation_warnings mechanism and 
passes testing. I wondered if in such cases we could alternately use the 
warning_sentinel mechanism (moved to cp-tree.h of course) ?

Thanks,
Paolo.

///////////////////

Comments

Jason Merrill Dec. 18, 2014, 2:20 p.m. UTC | #1
On 12/18/2014 06:17 AM, Paolo Carlini wrote:
> Sure. The below uses the c_inhibit_evaluation_warnings mechanism and
> passes testing. I wondered if in such cases we could alternately use the
> warning_sentinel mechanism (moved to cp-tree.h of course) ?

That would make sense to me.

Jason
diff mbox

Patch

Index: cp/semantics.c
===================================================================
--- cp/semantics.c	(revision 218857)
+++ cp/semantics.c	(working copy)
@@ -1660,7 +1660,9 @@  force_paren_expr (tree expr)
 	  tree type = unlowered_expr_type (expr);
 	  bool rval = !!(kind & clk_rvalueref);
 	  type = cp_build_reference_type (type, rval);
+	  ++c_inhibit_evaluation_warnings;
 	  expr = build_static_cast (type, expr, tf_error);
+	  --c_inhibit_evaluation_warnings;
 	  if (expr != error_mark_node)
 	    REF_PARENTHESIZED_P (expr) = true;
 	}
Index: cp/typeck.c
===================================================================
--- cp/typeck.c	(revision 218857)
+++ cp/typeck.c	(working copy)
@@ -6047,7 +6047,8 @@  cxx_mark_addressable (tree exp)
 		  ("address of explicit register variable %qD requested", x);
 		return false;
 	      }
-	    else if (extra_warnings)
+	    else if (extra_warnings
+		     && c_inhibit_evaluation_warnings == 0)
 	      warning
 		(OPT_Wextra, "address requested for %qD, which is declared %<register%>", x);
 	  }
Index: testsuite/g++.dg/warn/register-parm-1.C
===================================================================
--- testsuite/g++.dg/warn/register-parm-1.C	(revision 0)
+++ testsuite/g++.dg/warn/register-parm-1.C	(working copy)
@@ -0,0 +1,9 @@ 
+// PR c++/60955
+// { dg-options "-Wextra" }
+
+unsigned int erroneous_warning(register int a) {
+    if ((a) & 0xff) return 1; else return 0;
+}
+unsigned int no_erroneous_warning(register int a) {
+    if (a & 0xff) return 1; else return 0;
+}