public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: C++ PATCH for c++/51747 (list-initialization from same type)
Date: Fri, 11 Apr 2014 18:19:00 -0000	[thread overview]
Message-ID: <53483236.7030700@redhat.com> (raw)

[-- 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 } } }

             reply	other threads:[~2014-04-11 18:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-11 18:19 Jason Merrill [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53483236.7030700@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).