Hi,
On 03/12/2014 04:01 PM, Jason Merrill wrote:
Perhaps we need a require_potential_rvalue_constant_expression?
Something like the below? Interesting, that should also save some
duplicate work. Note however, that, besides the trivial adjustment of
static_assert3.C, we produce slightly different secondary diagnostic for
both static_assert10.C and static_assert11.C: for the former we notice
the non-constant 'int i' (*), for the latter the use of 'this'. Is that Ok?
Thanks,
Paolo.
//////////////////
(*) I double checked that if 'int i' is changed to 'const int i = 0' we
provide indeed the error message about the non-constexpr 'foo' as
secondary error message.
Index: cp/semantics.c
===================================================================
--- cp/semantics.c (revision 208507)
+++ cp/semantics.c (working copy)
@@ -6860,7 +6860,7 @@ finish_static_assert (tree condition, tree message
else if (condition && condition != error_mark_node)
{
error ("non-constant condition for static assertion");
- cxx_constant_value (condition);
+ require_potential_rvalue_constant_expression (condition);
}
input_location = saved_loc;
}
Index: testsuite/g++.dg/cpp0x/static_assert10.C
===================================================================
--- testsuite/g++.dg/cpp0x/static_assert10.C (revision 0)
+++ testsuite/g++.dg/cpp0x/static_assert10.C (working copy)
@@ -0,0 +1,8 @@
+// PR c++/60254
+// { dg-do compile { target c++11 } }
+
+template<typename T> bool foo(T)
+{
+ int i;
+ static_assert(foo(i), "Error"); // { dg-error "non-constant condition|not
usable" }
+}
Index: testsuite/g++.dg/cpp0x/static_assert11.C
===================================================================
--- testsuite/g++.dg/cpp0x/static_assert11.C (revision 0)
+++ testsuite/g++.dg/cpp0x/static_assert11.C (working copy)
@@ -0,0 +1,10 @@
+// PR c++/60254
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+ template<typename T> bool foo(T)
+ {
+ static_assert(foo(0), "Error"); // { dg-error "non-constant
condition|constant expression" }
+ }
+};
Index: testsuite/g++.dg/cpp0x/static_assert3.C
===================================================================
--- testsuite/g++.dg/cpp0x/static_assert3.C (revision 208507)
+++ testsuite/g++.dg/cpp0x/static_assert3.C (working copy)
@@ -1,4 +1,4 @@
// { dg-do compile { target c++11 } }
static_assert(7 / 0, "X"); // { dg-error "non-constant condition"
"non-constant" }
// { dg-warning "division by zero" "zero" { target *-*-* } 2 }
-// { dg-error "7 / 0.. is not a constant expression" "not a constant" { target
*-*-* } 2 }
+// { dg-error "division by zero is not a constant-expression" "non-constant" {
target *-*-* } 2 }