From patchwork Sat Mar 16 19:33:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 228245 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 185752C00B4 for ; Sun, 17 Mar 2013 06:33:23 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1364067205; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=/0nbBFL o5dpCiZPv5SfOx8Q/urY=; b=LTXx0xD50WaR+PyjMYAqUTlB8pog0ThOV7HEys9 LxKL+y6zAhwWllapYgAuoCRmzsC9N9I+6f3rKcTJ+fSY/Az7O1y50zzCpDewCXfl Jr5pwQDMs/sdWv0gPx+NzaKotQAG6f0HLHFpCe7RBzhr2O4KrleagSKf6KVFaqwK J9cs= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=c2zRa3n5AQSBcfkXsl5i+cnLuoiNAd+itMWXkjBRTurHYLBo/G3+4xuDF33n7N dqOjXLIjMPl+MpKq0amgvN+qNa74h+XhODcP4f8S4gtMQkw+rUNtEoXGMbcQqcJ1 ErcOXy+uHYVMzXlqqyi/2rHA367+jFJIkhuRHFUWtlM08=; Received: (qmail 3839 invoked by alias); 16 Mar 2013 19:33:15 -0000 Received: (qmail 3819 invoked by uid 22791); 16 Mar 2013 19:33:11 -0000 X-SWARE-Spam-Status: No, hits=-7.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_NV, TW_VF 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; Sat, 16 Mar 2013 19:33:07 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2GJX6ta014325 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 16 Mar 2013 15:33:07 -0400 Received: from [10.3.113.8] ([10.3.113.8]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r2GJX6xY028100 for ; Sat, 16 Mar 2013 15:33:06 -0400 Message-ID: <5144C8F1.2060306@redhat.com> Date: Sat, 16 Mar 2013 15:33:05 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Thunderbird/21.0a2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/54835 (value-list-initialization and 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 DR 1518 clarified that we need to check for the constructor being explicit even for value-initialization. Tested x86_64-pc-linux-gnu, applying to trunk. commit 5b4dec4223f320f314696b854481bbced847f1c9 Author: Jason Merrill Date: Sat Feb 16 10:10:05 2013 -0500 DR 1518 PR c++/54835 * call.c (convert_like_real): Check for explicit constructors even for value-initialization. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 530835b..e40c45f 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -5856,6 +5856,17 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, tree convfn = cand->fn; unsigned i; + /* 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) + /* Unless this is for direct-list-initialization. */ + && !(BRACE_ENCLOSED_INITIALIZER_P (expr) + && CONSTRUCTOR_IS_DIRECT_INIT (expr))) + { + error ("converting to %qT from initializer list would use " + "explicit constructor %qD", totype, convfn); + } + /* If we're initializing from {}, it's value-initialization. */ if (BRACE_ENCLOSED_INITIALIZER_P (expr) && CONSTRUCTOR_NELTS (expr) == 0 @@ -5874,20 +5885,6 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, expr = mark_rvalue_use (expr); - /* 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) - /* Unless this is for direct-list-initialization. */ - && !(BRACE_ENCLOSED_INITIALIZER_P (expr) - && CONSTRUCTOR_IS_DIRECT_INIT (expr)) - /* 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) - { - error ("converting to %qT from initializer list would use " - "explicit constructor %qD", totype, convfn); - } - /* Set user_conv_p on the argument conversions, so rvalue/base handling knows not to allow any more UDCs. */ for (i = 0; i < cand->num_convs; ++i) diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist40.C b/gcc/testsuite/g++.dg/cpp0x/initlist40.C index f270360..8cf36be 100644 --- a/gcc/testsuite/g++.dg/cpp0x/initlist40.C +++ b/gcc/testsuite/g++.dg/cpp0x/initlist40.C @@ -1,3 +1,4 @@ +// PR c++/54835, DR 1518 // { dg-options "-std=c++0x" } struct A @@ -7,6 +8,6 @@ struct A int main() { - A a1 = { }; + A a1 = { }; // { dg-error "explicit" } A a2 = { 24 }; // { dg-error "explicit" } }