aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2012-05-04 15:02:05 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2012-05-04 15:02:05 +0000
commitfb4bcc8d659011362117716d831829adaa02bdf3 (patch)
tree46a83e6c2ea8ac15132e01ee6c536631015b7c54
parent33e337e34d69a2e298be8b6c109b601c2986339b (diff)
downloadgcc-fb4bcc8d659011362117716d831829adaa02bdf3.zip
gcc-fb4bcc8d659011362117716d831829adaa02bdf3.tar.gz
gcc-fb4bcc8d659011362117716d831829adaa02bdf3.tar.bz2
re PR c++/53166 (static_assert produces bogus warning)
/cp 2012-05-04 Paolo Carlini <paolo.carlini@oracle.com> PR c++/53166 * pt.c (instantiate_class_template_1): Increase / decrease c_inhibit_evaluation_warnings around the tsubst_expr call for STATIC_ASSERT_CONDITION. (tsubst_expr, case STATIC_ASSERT): Likewise. * typeck.c (cp_build_binary_op, case EQ_EXPR/NE_EXPR): Check c_inhibit_evaluation_warnings in the OPT_Waddress warnings. /testsuite 2012-05-04 Paolo Carlini <paolo.carlini@oracle.com> PR c++/53166 * g++.dg/cpp0x/static_assert7.C: New. From-SVN: r187165
-rw-r--r--gcc/cp/ChangeLog10
-rw-r--r--gcc/cp/pt.c20
-rw-r--r--gcc/cp/typeck.c6
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/static_assert7.C20
5 files changed, 54 insertions, 7 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 46d8b89..560722c 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,13 @@
+2012-05-04 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/53166
+ * pt.c (instantiate_class_template_1): Increase / decrease
+ c_inhibit_evaluation_warnings around the tsubst_expr call
+ for STATIC_ASSERT_CONDITION.
+ (tsubst_expr, case STATIC_ASSERT): Likewise.
+ * typeck.c (cp_build_binary_op, case EQ_EXPR/NE_EXPR): Check
+ c_inhibit_evaluation_warnings in the OPT_Waddress warnings.
+
2012-05-03 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/53186
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index b720d4a..f14e040 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -8950,10 +8950,15 @@ instantiate_class_template_1 (tree type)
/* Build new TYPE_FIELDS. */
if (TREE_CODE (t) == STATIC_ASSERT)
{
- tree condition =
- tsubst_expr (STATIC_ASSERT_CONDITION (t), args,
- tf_warning_or_error, NULL_TREE,
- /*integral_constant_expression_p=*/true);
+ tree condition;
+
+ ++c_inhibit_evaluation_warnings;
+ condition =
+ tsubst_expr (STATIC_ASSERT_CONDITION (t), args,
+ tf_warning_or_error, NULL_TREE,
+ /*integral_constant_expression_p=*/true);
+ --c_inhibit_evaluation_warnings;
+
finish_static_assert (condition,
STATIC_ASSERT_MESSAGE (t),
STATIC_ASSERT_SOURCE_LOCATION (t),
@@ -13110,11 +13115,16 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
case STATIC_ASSERT:
{
- tree condition =
+ tree condition;
+
+ ++c_inhibit_evaluation_warnings;
+ condition =
tsubst_expr (STATIC_ASSERT_CONDITION (t),
args,
complain, in_decl,
/*integral_constant_expression_p=*/true);
+ --c_inhibit_evaluation_warnings;
+
finish_static_assert (condition,
STATIC_ASSERT_MESSAGE (t),
STATIC_ASSERT_SOURCE_LOCATION (t),
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index b59741c..4510d51 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -4081,7 +4081,8 @@ cp_build_binary_op (location_t location,
if (TREE_CODE (op0) == ADDR_EXPR
&& decl_with_nonnull_addr_p (TREE_OPERAND (op0, 0)))
{
- if (complain & tf_warning)
+ if ((complain & tf_warning)
+ && c_inhibit_evaluation_warnings == 0)
warning (OPT_Waddress, "the address of %qD will never be NULL",
TREE_OPERAND (op0, 0));
}
@@ -4093,7 +4094,8 @@ cp_build_binary_op (location_t location,
if (TREE_CODE (op1) == ADDR_EXPR
&& decl_with_nonnull_addr_p (TREE_OPERAND (op1, 0)))
{
- if (complain & tf_warning)
+ if ((complain & tf_warning)
+ && c_inhibit_evaluation_warnings == 0)
warning (OPT_Waddress, "the address of %qD will never be NULL",
TREE_OPERAND (op1, 0));
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e456366..4468854 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2012-05-04 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/53166
+ * g++.dg/cpp0x/static_assert7.C: New.
+
2012-05-04 Ulrich Weigand <ulrich.weigand@linaro.org>
PR tree-optimization/52633
diff --git a/gcc/testsuite/g++.dg/cpp0x/static_assert7.C b/gcc/testsuite/g++.dg/cpp0x/static_assert7.C
new file mode 100644
index 0000000..28793e4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/static_assert7.C
@@ -0,0 +1,20 @@
+// PR c++/53166
+// { dg-options "-std=c++11 -Waddress" }
+
+template <typename X, X a>
+struct A
+{
+ static_assert (a != nullptr, "oops");
+ static_assert (nullptr != a, "oops");
+
+ int f()
+ {
+ static_assert (a != nullptr, "oops");
+ static_assert (nullptr != a, "oops");
+ return 1;
+ }
+};
+
+int i1;
+A<int*, &i1> a1;
+int i2 = a1.f();