Hi,
I'm a bit nervous about the instantiated tree being a different kind of tree from the template one, such that TREE_NO_WARNING doesn't make sense on the new one. Maybe just check EXPR_P (r) as well.
I see, better be safe. The below still passes testing. Ok?
Thanks, Paolo. ////////////////////
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 (EXPR_P (r) && 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,