re PR c++/59231 (gcc misses [-Werror=sign-compare] when inside a template)

PR c++/59231
	PR c++/11586
	PR c++/14710
	PR c++/57132
gcc/
	* c-common.c (shorten_compare): Don't check
	c_inhibit_evaluation_warnings.
gcc/cp/
	* pt.c (struct warning_sentinel): New.
	(tsubst_copy_and_build): Use it instead of
	c_inhibit_evaluation_warnings.

From-SVN: r208183
This commit is contained in:
Jason Merrill 2014-02-26 16:28:08 -05:00 committed by Jason Merrill
parent 91bb5cd9a6
commit ca7e759d96
8 changed files with 57 additions and 23 deletions

View File

@ -1,3 +1,10 @@
2014-02-26 Jason Merrill <jason@redhat.com>
PR c++/59231
PR c++/11586
* c-common.c (shorten_compare): Don't check
c_inhibit_evaluation_warnings.
2014-02-19 Jakub Jelinek <jakub@redhat.com> 2014-02-19 Jakub Jelinek <jakub@redhat.com>
PR c/37743 PR c/37743

View File

@ -4218,8 +4218,7 @@ shorten_compare (location_t loc, tree *op0_ptr, tree *op1_ptr,
type = c_common_unsigned_type (type); 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) if (val == truthvalue_false_node)
warning_at (loc, OPT_Wtype_limits, warning_at (loc, OPT_Wtype_limits,
@ -4299,7 +4298,6 @@ shorten_compare (location_t loc, tree *op0_ptr, tree *op1_ptr,
warning. */ warning. */
bool warn = bool warn =
warn_type_limits && !in_system_header_at (loc) warn_type_limits && !in_system_header_at (loc)
&& c_inhibit_evaluation_warnings == 0
&& !(TREE_CODE (primop0) == INTEGER_CST && !(TREE_CODE (primop0) == INTEGER_CST
&& !TREE_OVERFLOW (convert (c_common_signed_type (type), && !TREE_OVERFLOW (convert (c_common_signed_type (type),
primop0))) primop0)))

View File

@ -1,5 +1,15 @@
2014-02-26 Jason Merrill <jason@redhat.com> 2014-02-26 Jason Merrill <jason@redhat.com>
PR c++/59231
PR c++/11586
PR c++/14710
PR c++/57132
* pt.c (struct warning_sentinel): New.
(tsubst_copy_and_build): Use it instead of
c_inhibit_evaluation_warnings.
* typeck.c (maybe_warn_about_useless_cast): Remove
c_inhibit_evaluation_warnings check.
PR c++/54440 PR c++/54440
* pt.c (get_template_parm_index): New. * pt.c (get_template_parm_index): New.
(fixed_parameter_pack_p_1, fixed_parameter_pack_p): New. (fixed_parameter_pack_p_1, fixed_parameter_pack_p): New.

View File

@ -1,4 +1,4 @@
/* Handle parameterized types (templates) for GNU C++. /* Handle parameterized types (templates) for GNU -*- C++ -*-.
Copyright (C) 1992-2014 Free Software Foundation, Inc. Copyright (C) 1992-2014 Free Software Foundation, Inc.
Written by Ken Raeburn (raeburn@cygnus.com) while at Watchmaker Computing. Written by Ken Raeburn (raeburn@cygnus.com) while at Watchmaker Computing.
Rewritten by Jason Merrill (jason@cygnus.com). Rewritten by Jason Merrill (jason@cygnus.com).
@ -14063,6 +14063,16 @@ tsubst_non_call_postfix_expression (tree t, tree args,
return t; return t;
} }
/* Sentinel to disable certain warnings during template substitution. */
struct warning_sentinel {
int &flag;
int val;
warning_sentinel(int& flag, bool suppress=true)
: flag(flag), val(flag) { if (suppress) flag = 0; }
~warning_sentinel() { flag = val; }
};
/* Like tsubst but deals with expressions and performs semantic /* Like tsubst but deals with expressions and performs semantic
analysis. FUNCTION_P is true if T is the "F" in "F (ARGS)". */ analysis. FUNCTION_P is true if T is the "F" in "F (ARGS)". */
@ -14229,7 +14239,7 @@ tsubst_copy_and_build (tree t,
op = RECUR (TREE_OPERAND (t, 0)); op = RECUR (TREE_OPERAND (t, 0));
++c_inhibit_evaluation_warnings; warning_sentinel s(warn_useless_cast);
switch (TREE_CODE (t)) switch (TREE_CODE (t))
{ {
case CAST_EXPR: case CAST_EXPR:
@ -14250,7 +14260,6 @@ tsubst_copy_and_build (tree t,
default: default:
gcc_unreachable (); gcc_unreachable ();
} }
--c_inhibit_evaluation_warnings;
RETURN (r); RETURN (r);
} }
@ -14325,11 +14334,9 @@ tsubst_copy_and_build (tree t,
case MEMBER_REF: case MEMBER_REF:
case DOTSTAR_EXPR: case DOTSTAR_EXPR:
{ {
tree r; warning_sentinel s1(warn_type_limits);
warning_sentinel s2(warn_div_by_zero);
++c_inhibit_evaluation_warnings; tree r = build_x_binary_op
r = build_x_binary_op
(input_location, TREE_CODE (t), (input_location, TREE_CODE (t),
RECUR (TREE_OPERAND (t, 0)), RECUR (TREE_OPERAND (t, 0)),
(TREE_NO_WARNING (TREE_OPERAND (t, 0)) (TREE_NO_WARNING (TREE_OPERAND (t, 0))
@ -14344,8 +14351,6 @@ tsubst_copy_and_build (tree t,
if (EXPR_P (r) && TREE_NO_WARNING (t)) if (EXPR_P (r) && TREE_NO_WARNING (t))
TREE_NO_WARNING (r) = TREE_NO_WARNING (t); TREE_NO_WARNING (r) = TREE_NO_WARNING (t);
--c_inhibit_evaluation_warnings;
RETURN (r); RETURN (r);
} }
@ -14460,11 +14465,8 @@ tsubst_copy_and_build (tree t,
case MODOP_EXPR: case MODOP_EXPR:
{ {
tree r; warning_sentinel s(warn_div_by_zero);
tree r = build_x_modify_expr
++c_inhibit_evaluation_warnings;
r = build_x_modify_expr
(EXPR_LOCATION (t), (EXPR_LOCATION (t),
RECUR (TREE_OPERAND (t, 0)), RECUR (TREE_OPERAND (t, 0)),
TREE_CODE (TREE_OPERAND (t, 1)), TREE_CODE (TREE_OPERAND (t, 1)),
@ -14479,8 +14481,6 @@ tsubst_copy_and_build (tree t,
if (TREE_NO_WARNING (t)) if (TREE_NO_WARNING (t))
TREE_NO_WARNING (r) = TREE_NO_WARNING (t); TREE_NO_WARNING (r) = TREE_NO_WARNING (t);
--c_inhibit_evaluation_warnings;
RETURN (r); RETURN (r);
} }

View File

@ -6282,8 +6282,7 @@ void
maybe_warn_about_useless_cast (tree type, tree expr, tsubst_flags_t complain) maybe_warn_about_useless_cast (tree type, tree expr, tsubst_flags_t complain)
{ {
if (warn_useless_cast if (warn_useless_cast
&& complain & tf_warning && complain & tf_warning)
&& c_inhibit_evaluation_warnings == 0)
{ {
if (REFERENCE_REF_P (expr)) if (REFERENCE_REF_P (expr))
expr = TREE_OPERAND (expr, 0); expr = TREE_OPERAND (expr, 0);

View File

@ -1,5 +1,5 @@
/* { dg-do run } */ /* { dg-do run } */
/* { dg-options "-fcilkplus" } */ /* { dg-options "-fcilkplus -Wno-overflow" } */
#include <cstdlib> #include <cstdlib>
#include <string.h> #include <string.h>

View File

@ -1,3 +1,5 @@
// { dg-prune-output "-Woverflow" }
template <long long i> template <long long i>
struct Fib struct Fib
{ {

View File

@ -0,0 +1,18 @@
// PR c++/59231
// { dg-options "-Wsign-compare" }
template<class X, class Y>
bool equals(X x, Y y)
{
return (x == y); // { dg-warning "signed" }
}
int main()
{
unsigned long x = 2;
signed int y = 2;
if(!equals (x, y))
return 1;
return 0;
}