Hi,
this small patch fixes the problem using the approach indicated by Jason
in the audit trail, already used in many other similar cases.
Booted and tested x86_64-linux.
Thanks,
Paolo.
/////////////////////////
/cp
2012-05-15 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/11586
* pt.c (tsubst_copy_and_build): Increase / decrease
c_inhibit_evaluation_warnings around build_x_binary_op call.
/c-family
2012-05-15 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/11586
* c-common.c (shorten_compare): Check c_inhibit_evaluation_warnings.
/testsuite
2012-05-15 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/11586
* g++.dg/warn/Wtype-limits.C: Don't warn in templates.
* g++.dg/warn/Wtype-limits-Wextra.C: Likewise.
Index: testsuite/g++.dg/warn/Wtype-limits-Wextra.C
===================================================================
--- testsuite/g++.dg/warn/Wtype-limits-Wextra.C (revision 187501)
+++ testsuite/g++.dg/warn/Wtype-limits-Wextra.C (working copy)
@@ -66,7 +66,7 @@ int test (int x)
template <typename Int, Int D>
void f(Int x) {
- assert(0 <= x and x <= D); // { dg-warning "comparison is always true due to
limited range of data type" }
+ assert(0 <= x and x <= D);
}
int ff(void) {
Index: testsuite/g++.dg/warn/Wtype-limits.C
===================================================================
--- testsuite/g++.dg/warn/Wtype-limits.C (revision 187501)
+++ testsuite/g++.dg/warn/Wtype-limits.C (working copy)
@@ -66,7 +66,7 @@ int test (int x)
template <typename Int, Int D>
void f(Int x) {
- assert(0 <= x and x <= D); // { dg-warning "comparison is always true due to
limited range of data type" }
+ assert(0 <= x and x <= D);
}
int ff(void) {
Index: cp/pt.c
===================================================================
--- cp/pt.c (revision 187501)
+++ cp/pt.c (working copy)
@@ -13608,7 +13610,11 @@ tsubst_copy_and_build (tree t,
case MEMBER_REF:
case DOTSTAR_EXPR:
{
- tree r = build_x_binary_op
+ tree r;
+
+ ++c_inhibit_evaluation_warnings;
+
+ r = build_x_binary_op
(input_location, TREE_CODE (t),
RECUR (TREE_OPERAND (t, 0)),
(TREE_NO_WARNING (TREE_OPERAND (t, 0))
@@ -13622,6 +13628,9 @@ tsubst_copy_and_build (tree t,
complain);
if (EXPR_P (r) && TREE_NO_WARNING (t))
TREE_NO_WARNING (r) = TREE_NO_WARNING (t);
+
+ --c_inhibit_evaluation_warnings;
+
return r;
}
Index: c-family/c-common.c
===================================================================
--- c-family/c-common.c (revision 187501)
+++ c-family/c-common.c (working copy)
@@ -3754,7 +3754,8 @@ shorten_compare (tree *op0_ptr, tree *op1_ptr, tre
type = c_common_unsigned_type (type);
}
- if (TREE_CODE (primop0) != INTEGER_CST)
+ if (TREE_CODE (primop0) != INTEGER_CST
+ && c_inhibit_evaluation_warnings == 0)
{
if (val == truthvalue_false_node)
warning_at (loc, OPT_Wtype_limits,
@@ -3834,6 +3835,7 @@ shorten_compare (tree *op0_ptr, tree *op1_ptr, tre
warning. */
bool warn =
warn_type_limits && !in_system_header
+ && c_inhibit_evaluation_warnings == 0
&& !(TREE_CODE (primop0) == INTEGER_CST
&& !TREE_OVERFLOW (convert (c_common_signed_type (type),
primop0)))