From patchwork Mon Apr 22 19:24:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 238654 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 79F322C0158 for ; Tue, 23 Apr 2013 05:25:09 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=xh4Acat/xa+Xr/fbThrbIrnb4JypxBH0UQj869QJoG1+CL +IoJE2FVjsLMaNDIMfDLUY9dOkvtCl/kQgNTydsR/155Hc8cWne8zwTuVq8vOYBh jFVE4dqd7tnng29V5R3Ryv0V4gYyIP3U3scvf31J2KY/qkM50K5x3gCerzGkM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=+ZDu+uZ8bSrKtu9MCGR77T1Rn7E=; b=cURtlTFvJ7wAh75ULOKD G2Mp3gOdDfq9rmC0nwlvVlM45w5sJAAlhLBgXQSGIQg4VDIN75bctMTBrmHh1ZBh txCYZAiKEFL3E1fJG4FySHY/JMoZHRiAKNib1tcx9rXFGFp+ncGsjQMnxo+cABL3 2128oOJMizstcq79jFhtQec= Received: (qmail 17978 invoked by alias); 22 Apr 2013 19:25:03 -0000 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 Received: (qmail 17963 invoked by uid 89); 22 Apr 2013 19:25:02 -0000 X-Spam-SWARE-Status: No, score=-6.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 22 Apr 2013 19:25:02 +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 r3MJP0Hg012052 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 22 Apr 2013 15:25:01 -0400 Received: from [10.36.116.23] (ovpn-116-23.ams2.redhat.com [10.36.116.23]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3MJOxWv015316 for ; Mon, 22 Apr 2013 15:25:00 -0400 Message-ID: <51758E8A.6010003@redhat.com> Date: Mon, 22 Apr 2013 15:24:58 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:22.0) Gecko/20100101 Thunderbird/22.0a2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH to implement conditional conversions (n3323) X-Virus-Found: No This paper corrected a defect in the language whereby we were prematurely rejecting as ambiguous a conversion required by a context, such as a delete-expression that wants some pointer type, when the class has multiple conversion operators to similar types. In many cases, we can resolve that using normal overload resolution; the only time we need to give up is when the conversion operators convert to different types. This paper was accepted after C++11, but it seems like a defect fix to me, so I'm not limiting it to C++1y mode. Tested x86_64-pc-linux-gnu, applying to trunk. commit 7e137f36fd739df81bc59fee16cc5548d3cb6207 Author: Jason Merrill Date: Mon Apr 22 14:03:58 2013 -0400 N3323 * cvt.c (build_expr_type_conversion): Two conversions that return the same type aren't necessarily ambiguous. diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index a3b7358..93be76a 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -1630,17 +1630,24 @@ build_expr_type_conversion (int desires, tree expr, bool complain) { if (winner) { - if (complain) + tree winner_type + = non_reference (TREE_TYPE (TREE_TYPE (winner))); + + if (!same_type_ignoring_top_level_qualifiers_p (winner_type, + candidate)) { - error ("ambiguous default type conversion from %qT", - basetype); - error (" candidate conversions include %qD and %qD", - winner, cand); + if (complain) + { + error ("ambiguous default type conversion from %qT", + basetype); + error (" candidate conversions include %qD and %qD", + winner, cand); + } + return error_mark_node; } - return error_mark_node; } - else - winner = cand; + + winner = cand; } } diff --git a/gcc/testsuite/g++.dg/cpp1y/context-conv1.C b/gcc/testsuite/g++.dg/cpp1y/context-conv1.C new file mode 100644 index 0000000..fe20cab --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/context-conv1.C @@ -0,0 +1,32 @@ +// N3323 + +#define assert(E) if(!(E))__builtin_abort(); + +template +class zero_init +{ +public: + zero_init( ) + : val( static_cast(0) ) { } + zero_init( T val ) : val( val ) + { } + operator T & ( ) { return val; } + operator T ( ) const { return val; } +private: + T val; +}; + +void f() +{ + zero_init p; assert( p == 0 ); + p = new int(7); + assert( *p == 7 ); + delete p; // error! + + zero_init i; assert( i == 0 ); + i = 7; + assert( i == 7 ); + switch( i ) { } // error! + + int *vp = new int[i]; +}