From patchwork Mon Feb 21 01:47:24 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 83772 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 1F94FB718C for ; Mon, 21 Feb 2011 12:47:37 +1100 (EST) Received: (qmail 22019 invoked by alias); 21 Feb 2011 01:47:34 -0000 Received: (qmail 22009 invoked by uid 22791); 21 Feb 2011 01:47:32 -0000 X-SWARE-Spam-Status: No, hits=-6.2 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; Mon, 21 Feb 2011 01:47:26 +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 p1L1lPPm030867 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 20 Feb 2011 20:47:25 -0500 Received: from [127.0.0.1] (ovpn-113-43.phx2.redhat.com [10.3.113.43]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p1L1lOvj011339 for ; Sun, 20 Feb 2011 20:47:24 -0500 Message-ID: <4D61C42C.2010901@redhat.com> Date: Sun, 20 Feb 2011 20:47:24 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/46831 (ICE with non-viable template conversion candidate) 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 convert_class_to_reference tries to massage candidates to provide the correct second standard conversion sequence, but that doesn't make any sense for candidates that are already known to be non-viable. And crashes. Tested x86_64-pc-linux-gnu, applied to trunk. commit 89b2cae8887f41a5c181b3c55fd24710cb78048c Author: Jason Merrill Date: Sun Feb 20 18:30:10 2011 -0500 PR c++/46831 * call.c (convert_class_to_reference): Don't try to set up a second conv sequence for non-viable candidates. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 7d602b9..078542a 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -1230,8 +1230,10 @@ convert_class_to_reference (tree reference_type, tree s, tree expr, int flags) rvalue of the right type is good enough. */ tree f = cand->fn; tree t2 = TREE_TYPE (TREE_TYPE (f)); - if (TREE_CODE (t2) != REFERENCE_TYPE - || !reference_compatible_p (t, TREE_TYPE (t2))) + if (cand->viable == 0) + /* Don't bother looking more closely. */; + else if (TREE_CODE (t2) != REFERENCE_TYPE + || !reference_compatible_p (t, TREE_TYPE (t2))) { /* No need to set cand->reason here; this is most likely an ambiguous match. If it's not, either this candidate diff --git a/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2.C b/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2.C new file mode 100644 index 0000000..12cc836 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/fntmpdefarg2.C @@ -0,0 +1,14 @@ +// PR c++/46831 +// { dg-options -std=c++0x } + +struct B { }; +struct D : B { }; +struct A { + template operator D&(); + operator long(); +}; + +void f(long); +void f(B&); + +int main() { f(A()); }