Hi again,

On 09/02/2014 04:28 PM, Jason Merrill wrote:
On 09/02/2014 10:17 AM, Paolo Carlini wrote:
Let's see if I can tease the case out...

I think you need to leave that hunk alone, and instead fix the new testcase by treating = {} more like {}, just as we already don't require a copy constructor call for copy-list-initialization.
By the way, now I really understand the DR (the wording in the resolution clarifies what we are *already* doing correctly!).

Anyway, what about the below? Certainly works for the tests which we have got.

Thanks,
Paolo.

////////////////////

Index: cp/semantics.c
===================================================================
--- cp/semantics.c      (revision 214808)
+++ cp/semantics.c      (working copy)
@@ -9859,11 +9859,14 @@ cxx_eval_outermost_constant_expr (tree t, bool all
   verify_constant (r, allow_non_constant, &non_constant_p, &overflow_p);
 
   if (TREE_CODE (t) != CONSTRUCTOR
+      && (TREE_CODE (t) != TARGET_EXPR
+         || TREE_CODE (TARGET_EXPR_INITIAL (t)) != AGGR_INIT_EXPR)
       && cp_has_mutable_p (TREE_TYPE (t)))
     {
       /* We allow a mutable type if the original expression was a
         CONSTRUCTOR so that we can do aggregate initialization of
-        constexpr variables.  */
+        constexpr variables.  Likewise for TARGET_EXPRs with an
+        AGGR_INIT_EXPR as TARGET_EXPR_INITIAL (c++/58102).  */
       if (!allow_non_constant)
        error ("%qT cannot be the type of a complete constant expression "
               "because it has mutable sub-objects", TREE_TYPE (t));
Index: testsuite/g++.dg/cpp0x/constexpr-mutable2.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-mutable2.C (revision 0)
+++ testsuite/g++.dg/cpp0x/constexpr-mutable2.C (working copy)
@@ -0,0 +1,10 @@
+// DR 1405, PR c++/58102
+// { dg-do compile { target c++11 } }
+
+struct S {
+  mutable int n;
+  constexpr S() : n() {}
+};
+
+constexpr S s1 {};
+constexpr S s2 = {};

Reply via email to