diff mbox

[C++] PR 57132

Message ID 5180F6D2.5020406@oracle.com
State New
Headers show

Commit Message

Paolo Carlini May 1, 2013, 11:04 a.m. UTC
Hi,

in tsubst_copy_and_build, particularly so after c++/11856, we are 
already wrapping the evaluation of most expressions in 
++c_inhibit_evaluation_warnings/--c_inhibit_evaluation_warnings, but we 
are failing to do so in case MODOP_EXPR. Tested x86_64-linux.

Ok for mainline?

Thanks,
Paolo.

///////////////////////////
/cp
2013-05-01  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/57132
	* pt.c (tsubst_copy_and_build, MODOP_EXPR): Increase / decrease
	c_inhibit_evaluation_warnings around build_x_modify_expr call.

/testsuite
2013-05-01  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/57132
	* g++.dg/warn/Wdiv-by-zero-bogus-2.C: New.

Comments

Jason Merrill May 1, 2013, 7:05 p.m. UTC | #1
OK.

Jason
diff mbox

Patch

Index: cp/pt.c
===================================================================
--- cp/pt.c	(revision 198488)
+++ cp/pt.c	(working copy)
@@ -13810,7 +13810,11 @@  tsubst_copy_and_build (tree t,
 
     case MODOP_EXPR:
       {
-	tree r = build_x_modify_expr
+	tree r;
+
+	++c_inhibit_evaluation_warnings;
+
+	r = build_x_modify_expr
 	  (EXPR_LOCATION (t),
 	   RECUR (TREE_OPERAND (t, 0)),
 	   TREE_CODE (TREE_OPERAND (t, 1)),
@@ -13824,6 +13828,9 @@  tsubst_copy_and_build (tree t,
 	   here.  */
 	if (TREE_NO_WARNING (t))
 	  TREE_NO_WARNING (r) = TREE_NO_WARNING (t);
+
+	--c_inhibit_evaluation_warnings;
+
 	RETURN (r);
       }
 
Index: testsuite/g++.dg/warn/Wdiv-by-zero-bogus-2.C
===================================================================
--- testsuite/g++.dg/warn/Wdiv-by-zero-bogus-2.C	(revision 0)
+++ testsuite/g++.dg/warn/Wdiv-by-zero-bogus-2.C	(working copy)
@@ -0,0 +1,18 @@ 
+// PR c++/57132
+
+template<unsigned m, unsigned a>
+struct mod 
+{
+  static unsigned calc(unsigned x) {
+    unsigned res = a * x;
+    if (m)
+      res %= m;
+    return res;
+  }
+};
+
+int main()
+{
+  mod<3,2>::calc(7);
+  mod<0,2>::calc(7);
+}