From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20830 invoked by alias); 11 Apr 2014 18:19:37 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 20817 invoked by uid 89); 11 Apr 2014 18:19:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.1 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 11 Apr 2014 18:19:36 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s3BIJZqc031955 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 11 Apr 2014 14:19:35 -0400 Received: from [10.10.116.16] ([10.10.116.16]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s3BIJYKc026685 for ; Fri, 11 Apr 2014 14:19:34 -0400 Message-ID: <53483236.7030700@redhat.com> Date: Fri, 11 Apr 2014 18:19:00 -0000 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/51747 (list-initialization from same type) Content-Type: multipart/mixed; boundary="------------070309050102010307090602" X-SW-Source: 2014-04/txt/msg00578.txt.bz2 This is a multi-part message in MIME format. --------------070309050102010307090602 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 232 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. --------------070309050102010307090602 Content-Type: text/x-patch; name="51747.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="51747.patch" Content-length: 1688 commit 0bb6493b9f08021d00a636fe5b4ea777bd4cbc13 Author: Jason Merrill 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 } } } --------------070309050102010307090602--