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.

///////////////////
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;
+}

Reply via email to