Hi,
we emit spurious -Wparentheses warnings for template arguments,
evidently because we are not propagating TREE_NO_WARNING during
tsubstitution.
I'm fixing the problem in a straightforward way, by using the same idiom
already used elsewhere: call build_x_binary_op and then propagate
TREE_NO_WARNING to the resulting tree before returning it. The testcase
is somewhat extended vs that in the PR: I wanted to exercise the warning
a bit more and double check that we are still producing it when in order.
Tested x86_64-linux.
Thanks,
Paolo.
///////////////////////
/cp
2012-01-04 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/51064
* pt.c (tsubst_copy_and_build): Maybe set TREE_NO_WARNING on
the tree returned by build_x_binary_op.
/testsuite
2012-01-04 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/51064
* g++.dg/warn/Wparentheses-26.C: New.
Index: testsuite/g++.dg/warn/Wparentheses-26.C
===================================================================
--- testsuite/g++.dg/warn/Wparentheses-26.C (revision 0)
+++ testsuite/g++.dg/warn/Wparentheses-26.C (revision 0)
@@ -0,0 +1,26 @@
+// PR c++/51064
+// { dg-options "-Wparentheses" }
+
+template<int i, int j = ((i + 7) >> 3)> class foo1 { };
+typedef foo1<10> bar1;
+
+template<int i, int j = (i + 7 >> 3)> class foo2 { };
+typedef foo2<10> bar2; // { dg-warning "suggest parentheses around '\\+'" }
+
+template<int i, int j = (100 >> (i + 2))> class foo3 { };
+typedef foo3<3> bar3;
+
+template<int i, int j = (100 >> i + 2)> class foo4 { };
+typedef foo4<3> bar4; // { dg-warning "suggest parentheses around '\\+'" }
+
+template<int i, int j = (i + 7) | 3> class foo5 { };
+typedef foo5<10> bar5;
+
+template<int i, int j = i + 7 | 3> class foo6 { };
+typedef foo6<10> bar6; // { dg-warning "suggest parentheses around
arithmetic" }
+
+template<int i, int j = 3 | (i + 7)> class foo7 { };
+typedef foo7<10> bar7;
+
+template<int i, int j = 3 | i + 7> class foo8 { };
+typedef foo8<10> bar8; // { dg-warning "suggest parentheses around
arithmetic" }
Index: cp/pt.c
===================================================================
--- cp/pt.c (revision 182870)
+++ cp/pt.c (working copy)
@@ -13563,18 +13563,23 @@ tsubst_copy_and_build (tree t,
case GT_EXPR:
case MEMBER_REF:
case DOTSTAR_EXPR:
- return build_x_binary_op
- (TREE_CODE (t),
- RECUR (TREE_OPERAND (t, 0)),
- (TREE_NO_WARNING (TREE_OPERAND (t, 0))
- ? ERROR_MARK
- : TREE_CODE (TREE_OPERAND (t, 0))),
- RECUR (TREE_OPERAND (t, 1)),
- (TREE_NO_WARNING (TREE_OPERAND (t, 1))
- ? ERROR_MARK
- : TREE_CODE (TREE_OPERAND (t, 1))),
- /*overload=*/NULL,
- complain);
+ {
+ tree r = build_x_binary_op
+ (TREE_CODE (t),
+ RECUR (TREE_OPERAND (t, 0)),
+ (TREE_NO_WARNING (TREE_OPERAND (t, 0))
+ ? ERROR_MARK
+ : TREE_CODE (TREE_OPERAND (t, 0))),
+ RECUR (TREE_OPERAND (t, 1)),
+ (TREE_NO_WARNING (TREE_OPERAND (t, 1))
+ ? ERROR_MARK
+ : TREE_CODE (TREE_OPERAND (t, 1))),
+ /*overload=*/NULL,
+ complain);
+ if (TREE_NO_WARNING (t))
+ TREE_NO_WARNING (r) = TREE_NO_WARNING (t);
+ return r;
+ }
case SCOPE_REF:
return tsubst_qualified_id (t, args, complain, in_decl, /*done=*/true,