public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/51747 (list-initialization from same type)
@ 2014-04-11 18:19 Jason Merrill
  2014-04-14 22:03 ` Marc Glisse
  2015-05-07 16:45 ` Jason Merrill
  0 siblings, 2 replies; 9+ messages in thread
From: Jason Merrill @ 2014-04-11 18:19 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 232 bytes --]

Recent changes to the C++ standard have allowed the use of 
list-initialization with a single initializer of the same type as the 
target; this patch updates reshape_init accordingly.

Tested x86_64-pc-linux-gnu, applying to trunk.

[-- Attachment #2: 51747.patch --]
[-- Type: text/x-patch, Size: 1688 bytes --]

commit 0bb6493b9f08021d00a636fe5b4ea777bd4cbc13
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Mar 21 06:15:02 2014 -0400

    	DR 1467
    	PR c++/51747
    	* decl.c (reshape_init_r): Handle a single element of class type.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 069b374..f8ae07c 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5405,6 +5405,18 @@ reshape_init_r (tree type, reshape_iter *d, bool first_initializer_p,
       return init;
     }
 
+  /* "If T is a class type and the initializer list has a single element of
+     type cv U, where U is T or a class derived from T, the object is
+     initialized from that element."  Even if T is an aggregate.  */
+  if (cxx_dialect >= cxx11 && CLASS_TYPE_P (type)
+      && first_initializer_p
+      && d->end - d->cur == 1
+      && reference_related_p (type, TREE_TYPE (init)))
+    {
+      d->cur++;
+      return init;
+    }
+
   /* [dcl.init.aggr]
 
      All implicit type conversions (clause _conv_) are considered when
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist83.C b/gcc/testsuite/g++.dg/cpp0x/initlist83.C
new file mode 100644
index 0000000..4a5eeb6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist83.C
@@ -0,0 +1,7 @@
+// DR 1467, c++/51747
+// { dg-do compile { target c++11 } }
+
+struct X { };
+
+X x;
+X x2{x};
diff --git a/gcc/testsuite/g++.dg/init/aggr4.C b/gcc/testsuite/g++.dg/init/aggr4.C
index 7120e68..b0eae2e 100644
--- a/gcc/testsuite/g++.dg/init/aggr4.C
+++ b/gcc/testsuite/g++.dg/init/aggr4.C
@@ -4,4 +4,4 @@ struct A
 };
 
 A a1 = { 1 };			// ok
-A a2 = { a1 };			// { dg-error "cannot convert" }
+A a2 = { a1 };	 // { dg-error "cannot convert" "" { target { ! c++11 } } }

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: C++ PATCH for c++/51747 (list-initialization from same type)
  2014-04-11 18:19 C++ PATCH for c++/51747 (list-initialization from same type) Jason Merrill
@ 2014-04-14 22:03 ` Marc Glisse
  2014-04-15 14:01   ` Jason Merrill
  2015-05-07 16:45 ` Jason Merrill
  1 sibling, 1 reply; 9+ messages in thread
From: Marc Glisse @ 2014-04-14 22:03 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches List

On Fri, 11 Apr 2014, Jason Merrill wrote:

> Recent changes to the C++ standard have allowed the use of 
> list-initialization with a single initializer of the same type as the target; 
> this patch updates reshape_init accordingly.
>
> Tested x86_64-pc-linux-gnu, applying to trunk.

Hello,

shouldn't the same also apply if VECTOR_TYPE_P (type), not just for 
CLASS_TYPE_P (type)?

Testcase in:
http://stackoverflow.com/questions/23070982/c-initialization-of-intel-simd-intrinsics-class-members

-- 
Marc Glisse

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: C++ PATCH for c++/51747 (list-initialization from same type)
  2014-04-14 22:03 ` Marc Glisse
@ 2014-04-15 14:01   ` Jason Merrill
  2014-04-15 14:13     ` Marc Glisse
  0 siblings, 1 reply; 9+ messages in thread
From: Jason Merrill @ 2014-04-15 14:01 UTC (permalink / raw)
  To: Marc Glisse; +Cc: gcc-patches List

On 04/14/2014 06:02 PM, Marc Glisse wrote:
> shouldn't the same also apply if VECTOR_TYPE_P (type), not just for
> CLASS_TYPE_P (type)?

Sure.  Do you want to make that change?

Jason

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: C++ PATCH for c++/51747 (list-initialization from same type)
  2014-04-15 14:01   ` Jason Merrill
@ 2014-04-15 14:13     ` Marc Glisse
  2014-04-15 14:59       ` Jason Merrill
  0 siblings, 1 reply; 9+ messages in thread
From: Marc Glisse @ 2014-04-15 14:13 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches List

On Tue, 15 Apr 2014, Jason Merrill wrote:

> On 04/14/2014 06:02 PM, Marc Glisse wrote:
>> shouldn't the same also apply if VECTOR_TYPE_P (type), not just for
>> CLASS_TYPE_P (type)?
>
> Sure.  Do you want to make that change?

I can add || VECTOR_TYPE_P (type), yes, but I thought you might have ideas 
about other cases that might have been forgotten, maybe arrays or 
something (I didn't have time to test any further), and thus on what the 
right test should be. If it is just vectors I'll prepare a patch with a 
simple testcase.

-- 
Marc Glisse

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: C++ PATCH for c++/51747 (list-initialization from same type)
  2014-04-15 14:13     ` Marc Glisse
@ 2014-04-15 14:59       ` Jason Merrill
  2014-04-15 21:02         ` Marc Glisse
  0 siblings, 1 reply; 9+ messages in thread
From: Jason Merrill @ 2014-04-15 14:59 UTC (permalink / raw)
  To: Marc Glisse; +Cc: gcc-patches List

On 04/15/2014 10:13 AM, Marc Glisse wrote:
> I can add || VECTOR_TYPE_P (type), yes, but I thought you might have
> ideas about other cases that might have been forgotten, maybe arrays or
> something (I didn't have time to test any further), and thus on what the
> right test should be. If it is just vectors I'll prepare a patch with a
> simple testcase.

It's just vectors, because they're an extension; the patch I checked in 
covered the standard language.

Jason

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: C++ PATCH for c++/51747 (list-initialization from same type)
  2014-04-15 14:59       ` Jason Merrill
@ 2014-04-15 21:02         ` Marc Glisse
  2014-04-16 17:26           ` Jason Merrill
  0 siblings, 1 reply; 9+ messages in thread
From: Marc Glisse @ 2014-04-15 21:02 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches List

[-- Attachment #1: Type: TEXT/PLAIN, Size: 397 bytes --]

On Tue, 15 Apr 2014, Jason Merrill wrote:

> It's just vectors, because they're an extension; the patch I checked in 
> covered the standard language.

Like this? (regtested on x86_64-linux-gnu)

2014-04-16  Marc Glisse  <marc.glisse@inria.fr>

gcc/cp/
 	* decl.c (reshape_init_r): Handle a single element of vector type.
gcc/testsuite/
 	* g++.dg/cpp0x/initlist-vect.C: New file.

-- 
Marc Glisse

[-- Attachment #2: Type: TEXT/PLAIN, Size: 1286 bytes --]

Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 209434)
+++ gcc/cp/decl.c	(working copy)
@@ -5400,21 +5400,21 @@ reshape_init_r (tree type, reshape_iter
 	    maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
 	}
 
       d->cur++;
       return init;
     }
 
   /* "If T is a class type and the initializer list has a single element of
      type cv U, where U is T or a class derived from T, the object is
      initialized from that element."  Even if T is an aggregate.  */
-  if (cxx_dialect >= cxx11 && CLASS_TYPE_P (type)
+  if (cxx_dialect >= cxx11 && (CLASS_TYPE_P (type) || VECTOR_TYPE_P (type))
       && first_initializer_p
       && d->end - d->cur == 1
       && reference_related_p (type, TREE_TYPE (init)))
     {
       d->cur++;
       return init;
     }
 
   /* [dcl.init.aggr]
 
Index: gcc/testsuite/g++.dg/cpp0x/initlist-vect.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/initlist-vect.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/initlist-vect.C	(working copy)
@@ -0,0 +1,6 @@
+// { dg-do compile { target c++11 } }
+
+typedef float X __attribute__ ((vector_size (4 * sizeof (float))));
+
+X x;
+X x2{x};

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: C++ PATCH for c++/51747 (list-initialization from same type)
  2014-04-15 21:02         ` Marc Glisse
@ 2014-04-16 17:26           ` Jason Merrill
  0 siblings, 0 replies; 9+ messages in thread
From: Jason Merrill @ 2014-04-16 17:26 UTC (permalink / raw)
  To: Marc Glisse; +Cc: gcc-patches List

OK.

Jason

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: C++ PATCH for c++/51747 (list-initialization from same type)
  2014-04-11 18:19 C++ PATCH for c++/51747 (list-initialization from same type) Jason Merrill
  2014-04-14 22:03 ` Marc Glisse
@ 2015-05-07 16:45 ` Jason Merrill
  2015-06-09 17:07   ` Jason Merrill
  1 sibling, 1 reply; 9+ messages in thread
From: Jason Merrill @ 2015-05-07 16:45 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 93 bytes --]

We also need to adjust digest_init_r.

Tested x86_64-pc-linux-gnu, applying to trunk and 5.


[-- Attachment #2: 51747-2.patch --]
[-- Type: text/x-patch, Size: 1486 bytes --]

commit 23cbda06982fbaf061719dff124ae90c3b033d7e
Author: Jason Merrill <jason@redhat.com>
Date:   Wed May 6 17:11:54 2015 -0500

    	DR 1467
    	PR c++/51747
    	* typeck2.c (digest_init_r): Fix single element list.

diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 6e0c777..076f9a0 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -1096,6 +1096,19 @@ digest_init_r (tree type, tree init, bool nested, int flags,
 	      || TREE_CODE (type) == UNION_TYPE
 	      || TREE_CODE (type) == COMPLEX_TYPE);
 
+  /* "If T is a class type and the initializer list has a single
+     element of type cv U, where U is T or a class derived from T,
+     the object is initialized from that element."  */
+  if (cxx_dialect >= cxx11
+      && BRACE_ENCLOSED_INITIALIZER_P (init)
+      && CONSTRUCTOR_NELTS (init) == 1
+      && (CLASS_TYPE_P (type) || VECTOR_TYPE_P (type)))
+    {
+      tree elt = CONSTRUCTOR_ELT (init, 0)->value;
+      if (reference_related_p (type, TREE_TYPE (elt)))
+	init = elt;
+    }
+
   if (BRACE_ENCLOSED_INITIALIZER_P (init)
       && !TYPE_NON_AGGREGATE_CLASS (type))
     return process_init_constructor (type, init, complain);
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist95.C b/gcc/testsuite/g++.dg/cpp0x/initlist95.C
new file mode 100644
index 0000000..fe2c8f6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist95.C
@@ -0,0 +1,5 @@
+// PR c++/51747
+// { dg-do compile { target c++11 } }
+
+struct B {};
+struct D : B {D(B b) : B{b} {}};

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: C++ PATCH for c++/51747 (list-initialization from same type)
  2015-05-07 16:45 ` Jason Merrill
@ 2015-06-09 17:07   ` Jason Merrill
  0 siblings, 0 replies; 9+ messages in thread
From: Jason Merrill @ 2015-06-09 17:07 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 210 bytes --]

On 05/07/2015 12:45 PM, Jason Merrill wrote:
> We also need to adjust digest_init_r.

This was only needed because we weren't calling reshape_init.  Now that 
Paolo has fixed that, this can become an assert.



[-- Attachment #2: 51747-unr.patch --]
[-- Type: text/x-patch, Size: 1148 bytes --]

commit 8d2793c42fc3de4a0b665f4c2ff2a2946ae0beda
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Jun 9 09:51:31 2015 -0400

    	DR 1467
    	PR c++/51747
    	* typeck2.c (digest_init_r): Replace previous change with
    	gcc_unreachable.

diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index b077f02..709875c 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -1089,6 +1089,7 @@ digest_init_r (tree type, tree init, bool nested, int flags,
 	      || TREE_CODE (type) == UNION_TYPE
 	      || TREE_CODE (type) == COMPLEX_TYPE);
 
+#ifdef ENABLE_CHECKING
   /* "If T is a class type and the initializer list has a single
      element of type cv U, where U is T or a class derived from T,
      the object is initialized from that element."  */
@@ -1099,8 +1100,10 @@ digest_init_r (tree type, tree init, bool nested, int flags,
     {
       tree elt = CONSTRUCTOR_ELT (init, 0)->value;
       if (reference_related_p (type, TREE_TYPE (elt)))
-	init = elt;
+	/* We should have fixed this in reshape_init.  */
+	gcc_unreachable ();
     }
+#endif
 
   if (BRACE_ENCLOSED_INITIALIZER_P (init)
       && !TYPE_NON_AGGREGATE_CLASS (type))

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-06-09 16:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-11 18:19 C++ PATCH for c++/51747 (list-initialization from same type) Jason Merrill
2014-04-14 22:03 ` Marc Glisse
2014-04-15 14:01   ` Jason Merrill
2014-04-15 14:13     ` Marc Glisse
2014-04-15 14:59       ` Jason Merrill
2014-04-15 21:02         ` Marc Glisse
2014-04-16 17:26           ` Jason Merrill
2015-05-07 16:45 ` Jason Merrill
2015-06-09 17:07   ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).