Patchwork [C++] PR 58102 aka DR 1405

login
register
mail settings
Submitter Paolo Carlini
Date Sept. 1, 2014, 1:47 p.m.
Message ID <5404790A.8020402@oracle.com>
Download mbox | patch
Permalink /patch/384854/
State New
Headers show

Comments

Paolo Carlini - Sept. 1, 2014, 1:47 p.m.
Hi,

I think that in order to implement the resolution we simply have to 
remove the check. Tested x86_64-linux.

Thanks,
Paolo.

//////////////////////
/cp
2014-09-01  Paolo Carlini  <paolo.carlini@oracle.com>

	DR 1405
	PR c++/58102
	* semantics.c (cxx_eval_outermost_constant_expr): Do not check
	for mutable sub-objects.

/testsuite
2014-09-01  Paolo Carlini  <paolo.carlini@oracle.com>

	DR 1405
	PR c++/58102
	* g++.dg/cpp0x/constexpr-mutable2.C: New.
	* g++.dg/cpp0x/constexpr-mutable1.C: Adjust.
Jason Merrill - Sept. 2, 2014, 2:11 p.m.
On 09/01/2014 09:47 AM, Paolo Carlini wrote:
> -constexpr A b = a;		// { dg-error "mutable" }
> +constexpr A b = a;

This is wrong; we still need to get an error here.

Jason
Paolo Carlini - Sept. 2, 2014, 2:17 p.m.
Hi,

On 09/02/2014 04:11 PM, Jason Merrill wrote:
> On 09/01/2014 09:47 AM, Paolo Carlini wrote:
>> -constexpr A b = a;        // { dg-error "mutable" }
>> +constexpr A b = a;
>
> This is wrong; we still need to get an error here.
Hum, interesting. Neither current EDG nor current clang error out there. 
Let's see if I can tease the case out...

Thanks,
Paolo.
Jason Merrill - Sept. 2, 2014, 2:28 p.m.
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.

Jason
Paolo Carlini - Sept. 2, 2014, 2:30 p.m.
Hi,

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.
I see. Thanks a lot for the tip!

Paolo.

Patch

Index: cp/semantics.c
===================================================================
--- cp/semantics.c	(revision 214779)
+++ cp/semantics.c	(working copy)
@@ -9858,18 +9858,6 @@  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
-      && 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.  */
-      if (!allow_non_constant)
-	error ("%qT cannot be the type of a complete constant expression "
-	       "because it has mutable sub-objects", TREE_TYPE (t));
-      non_constant_p = true;
-    }
-
   /* Technically we should check this for all subexpressions, but that
      runs into problems with our internal representation of pointer
      subtraction and the 5.19 rules are still in flux.  */
Index: testsuite/g++.dg/cpp0x/constexpr-mutable1.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-mutable1.C	(revision 214785)
+++ testsuite/g++.dg/cpp0x/constexpr-mutable1.C	(working copy)
@@ -7,6 +7,6 @@  struct A
 };
 
 constexpr A a = { 0, 1 };
-constexpr A b = a;		// { dg-error "mutable" }
+constexpr A b = a;
 constexpr int i = a.i;
 constexpr int j = a.j;		// { dg-error "mutable" }
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 = {};