aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2014-02-26 16:28:08 -0500
committerJason Merrill <jason@gcc.gnu.org>2014-02-26 16:28:08 -0500
commitca7e759d96d6c0c046a6e20b066d86d070f65e35 (patch)
treec3f90cee49d19ad5f42089ff43c724ba922a1322 /gcc
parent91bb5cd9a60c4ecd438e57980b405d6abd076972 (diff)
downloadgcc-ca7e759d96d6c0c046a6e20b066d86d070f65e35.zip
gcc-ca7e759d96d6c0c046a6e20b066d86d070f65e35.tar.gz
gcc-ca7e759d96d6c0c046a6e20b066d86d070f65e35.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c-family/ChangeLog7
-rw-r--r--gcc/c-family/c-common.c4
-rw-r--r--gcc/cp/ChangeLog10
-rw-r--r--gcc/cp/pt.c34
-rw-r--r--gcc/cp/typeck.c3
-rw-r--r--gcc/testsuite/g++.dg/cilk-plus/AN/array_test2_tplt.cc2
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/overflow1.C2
-rw-r--r--gcc/testsuite/g++.dg/warn/Wsign-compare-7.C18
8 files changed, 57 insertions, 23 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 2bb5935..088d158a 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -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>
PR c/37743
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index e23a9df..abd96fb 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -4218,8 +4218,7 @@ shorten_compare (location_t loc, tree *op0_ptr, tree *op1_ptr,
type = c_common_unsigned_type (type);
}
- if (TREE_CODE (primop0) != INTEGER_CST
- && c_inhibit_evaluation_warnings == 0)
+ if (TREE_CODE (primop0) != INTEGER_CST)
{
if (val == truthvalue_false_node)
warning_at (loc, OPT_Wtype_limits,
@@ -4299,7 +4298,6 @@ shorten_compare (location_t loc, tree *op0_ptr, tree *op1_ptr,
warning. */
bool warn =
warn_type_limits && !in_system_header_at (loc)
- && c_inhibit_evaluation_warnings == 0
&& !(TREE_CODE (primop0) == INTEGER_CST
&& !TREE_OVERFLOW (convert (c_common_signed_type (type),
primop0)))
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f1f1195..41a0db6 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,15 @@
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
* pt.c (get_template_parm_index): New.
(fixed_parameter_pack_p_1, fixed_parameter_pack_p): New.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 1f5a2b7..8126905 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -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.
Written by Ken Raeburn (raeburn@cygnus.com) while at Watchmaker Computing.
Rewritten by Jason Merrill (jason@cygnus.com).
@@ -14063,6 +14063,16 @@ tsubst_non_call_postfix_expression (tree t, tree args,
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
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));
- ++c_inhibit_evaluation_warnings;
+ warning_sentinel s(warn_useless_cast);
switch (TREE_CODE (t))
{
case CAST_EXPR:
@@ -14250,7 +14260,6 @@ tsubst_copy_and_build (tree t,
default:
gcc_unreachable ();
}
- --c_inhibit_evaluation_warnings;
RETURN (r);
}
@@ -14325,11 +14334,9 @@ tsubst_copy_and_build (tree t,
case MEMBER_REF:
case DOTSTAR_EXPR:
{
- tree r;
-
- ++c_inhibit_evaluation_warnings;
-
- r = build_x_binary_op
+ warning_sentinel s1(warn_type_limits);
+ warning_sentinel s2(warn_div_by_zero);
+ tree r = build_x_binary_op
(input_location, TREE_CODE (t),
RECUR (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))
TREE_NO_WARNING (r) = TREE_NO_WARNING (t);
- --c_inhibit_evaluation_warnings;
-
RETURN (r);
}
@@ -14460,11 +14465,8 @@ tsubst_copy_and_build (tree t,
case MODOP_EXPR:
{
- tree r;
-
- ++c_inhibit_evaluation_warnings;
-
- r = build_x_modify_expr
+ warning_sentinel s(warn_div_by_zero);
+ tree r = build_x_modify_expr
(EXPR_LOCATION (t),
RECUR (TREE_OPERAND (t, 0)),
TREE_CODE (TREE_OPERAND (t, 1)),
@@ -14479,8 +14481,6 @@ tsubst_copy_and_build (tree t,
if (TREE_NO_WARNING (t))
TREE_NO_WARNING (r) = TREE_NO_WARNING (t);
- --c_inhibit_evaluation_warnings;
-
RETURN (r);
}
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 5fc0e6b..1e14b63 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -6282,8 +6282,7 @@ void
maybe_warn_about_useless_cast (tree type, tree expr, tsubst_flags_t complain)
{
if (warn_useless_cast
- && complain & tf_warning
- && c_inhibit_evaluation_warnings == 0)
+ && complain & tf_warning)
{
if (REFERENCE_REF_P (expr))
expr = TREE_OPERAND (expr, 0);
diff --git a/gcc/testsuite/g++.dg/cilk-plus/AN/array_test2_tplt.cc b/gcc/testsuite/g++.dg/cilk-plus/AN/array_test2_tplt.cc
index 87c37e1..041c052 100644
--- a/gcc/testsuite/g++.dg/cilk-plus/AN/array_test2_tplt.cc
+++ b/gcc/testsuite/g++.dg/cilk-plus/AN/array_test2_tplt.cc
@@ -1,5 +1,5 @@
/* { dg-do run } */
-/* { dg-options "-fcilkplus" } */
+/* { dg-options "-fcilkplus -Wno-overflow" } */
#include <cstdlib>
#include <string.h>
diff --git a/gcc/testsuite/g++.dg/cpp0x/overflow1.C b/gcc/testsuite/g++.dg/cpp0x/overflow1.C
index 7033e9c..b8591b4 100644
--- a/gcc/testsuite/g++.dg/cpp0x/overflow1.C
+++ b/gcc/testsuite/g++.dg/cpp0x/overflow1.C
@@ -1,3 +1,5 @@
+// { dg-prune-output "-Woverflow" }
+
template <long long i>
struct Fib
{
diff --git a/gcc/testsuite/g++.dg/warn/Wsign-compare-7.C b/gcc/testsuite/g++.dg/warn/Wsign-compare-7.C
new file mode 100644
index 0000000..51f13f6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wsign-compare-7.C
@@ -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;
+}