From patchwork Tue Jun 15 19:26:43 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 55787 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 0F1D4B7DA5 for ; Wed, 16 Jun 2010 05:26:55 +1000 (EST) Received: (qmail 3114 invoked by alias); 15 Jun 2010 19:26:54 -0000 Received: (qmail 3104 invoked by uid 22791); 15 Jun 2010 19:26:53 -0000 X-SWARE-Spam-Status: No, hits=-5.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 15 Jun 2010 19:26:49 +0000 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5FJQj7l009775 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 15 Jun 2010 15:26:46 -0400 Received: from [IPv6:::1] (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5FJQhSG015534 for ; Tue, 15 Jun 2010 15:26:44 -0400 Message-ID: <4C17D3F3.9070409@redhat.com> Date: Tue, 15 Jun 2010 15:26:43 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.10) Gecko/20100603 Lightning/1.0b1 Shredder/3.0.6pre MIME-Version: 1.0 To: gcc-patches List Subject: C++0x PATCH for list value-initialization vs explicit constructors Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org In this testcase, we are list-initializing from {}. The FCD says that this means we should value-initialize the target. We were then giving an error about using an explicit constructor, which doesn't apply in this case because we aren't using the normal list-initialization overload resolution rules, we're just value-initializing. Tested x86_64-pc-linux-gnu, applying to trunk. commit 4a67f791e454f5d04c8eabd0358b32e971ee0146 Author: Jason Merrill Date: Tue Jun 15 01:08:24 2010 -0400 * call.c (convert_like_real): Don't complain about list-value-initialization from an explicit constructor. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 9ce1c53..60d7333 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -4956,7 +4956,10 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, /* When converting from an init list we consider explicit constructors, but actually trying to call one is an error. */ - if (DECL_NONCONVERTING_P (convfn) && DECL_CONSTRUCTOR_P (convfn)) + if (DECL_NONCONVERTING_P (convfn) && DECL_CONSTRUCTOR_P (convfn) + /* Unless we're calling it for value-initialization from an + empty list, since that is handled separately in 8.5.4. */ + && cand->num_convs > 0) { if (complain & tf_error) error ("converting to %qT from initializer list would use " diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist40.C b/gcc/testsuite/g++.dg/cpp0x/initlist40.C new file mode 100644 index 0000000..f270360 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist40.C @@ -0,0 +1,12 @@ +// { dg-options "-std=c++0x" } + +struct A +{ + explicit A(int = 42); +}; + +int main() +{ + A a1 = { }; + A a2 = { 24 }; // { dg-error "explicit" } +}