Hi,

On 03/12/2014 10:28 PM, Jason Merrill wrote:
On 03/12/2014 12:12 PM, Paolo Carlini wrote:
-      cxx_constant_value (condition);
+      require_potential_rvalue_constant_expression (condition);

We need both, actually; cxx_constant_value catches some cases that the other doesn't.
Ok, I think I got confused when I compared to cxx_alignas_expr: in the present case 'condition' is already the result of maybe_constant_value (thus it seems we would waste work) but, at variance with cxx_constant_value called by the former, it allows for nonconstants, and we want to emit at this point also the errors suppressed the first time cxx_eval_outermost_constant_expr is called... Thanks for your patience, now the various *_constant_* helpers are more clear ;)

The below also passes testing.

Thanks,
Paolo.

///////////////////
Index: cp/semantics.c
===================================================================
--- cp/semantics.c      (revision 208507)
+++ cp/semantics.c      (working copy)
@@ -6860,7 +6860,8 @@ 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);
+         if (require_potential_rvalue_constant_expression (condition))
+           cxx_constant_value (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" "not a constant" 
{ target *-*-* } 2 }

Reply via email to