From patchwork Mon Feb 6 20:56:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 139796 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 C9CAF1007D1 for ; Tue, 7 Feb 2012 08:08:24 +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=1329167305; h=Comment: DomainKey-Signature:Received: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=+clD/xo bHsHxxnvbuv60Ut/qRpo=; b=iF+xTqt2DX9Y9KL3qMl7gngPymf+0lhpKA0GaBB w6OvPhiUy+0w6dnJHfUD4X0o4zRATE5GAv1C01LdUKlD8gHTuBX/R06XtEsf3pHG FcL0794zXW5COBtQCyfB47gbBQN9w7YOoFhw/3c/VYa4N6/BVS61aCut4VDA7omc UFAs= 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: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=q/a1R5o3OkCjcvNZ9EFi1Gq53GqZN7BefoHd4O6xHse7+t/qVgS6vULGVzE1k2 JCUHrSlIH9wkBNOJjwtQFqjTDAaiUdL6pTBAbkfTQf2qBwTXsog+o7CvPydjXkRH OAbWpakfVjHvPTu+f+gMNZM4okzHn5eHcMkYSr7fM3gxU=; Received: (qmail 20825 invoked by alias); 6 Feb 2012 21:08:21 -0000 Received: (qmail 20815 invoked by uid 22791); 6 Feb 2012 21:08:21 -0000 X-SWARE-Spam-Status: No, hits=-6.6 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, 06 Feb 2012 21:08:08 +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 q16L88uV016330 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 6 Feb 2012 16:08:08 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q16KuhMe000684 for ; Mon, 6 Feb 2012 15:56:43 -0500 Received: from [0.0.0.0] (ovpn-113-149.phx2.redhat.com [10.3.113.149]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id q16KufO3022576 for ; Mon, 6 Feb 2012 15:56:42 -0500 Message-ID: <4F303E89.3070502@redhat.com> Date: Mon, 06 Feb 2012 10:56:41 -1000 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:9.0) Gecko/20111222 Thunderbird/9.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/52088 (ICE with template conversion op) 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 ended up trying to call an uninstantiated template, and get confused as a result. This patch changes the compiler to not consider a template to be a valid candidate for a default conversion. Tested x86_64-pc-linux-gnu, applied to trunk commit 06d4f1b83e5c393fd22421bbd12135338b891f8e Author: Jason Merrill Date: Sun Feb 5 22:36:59 2012 -1000 PR c++/52088 * cvt.c (build_expr_type_conversion): Check for template conversion. diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index 8570e3d..c411a47 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -1539,6 +1539,17 @@ build_expr_type_conversion (int desires, tree expr, bool complain) if (DECL_NONCONVERTING_P (cand)) continue; + if (TREE_CODE (cand) == TEMPLATE_DECL) + { + if (complain) + { + error ("ambiguous default type conversion from %qT", + basetype); + error (" candidate conversions include %qD", cand); + } + return error_mark_node; + } + candidate = non_reference (TREE_TYPE (TREE_TYPE (cand))); switch (TREE_CODE (candidate)) diff --git a/gcc/testsuite/g++.dg/template/conv13.C b/gcc/testsuite/g++.dg/template/conv13.C new file mode 100644 index 0000000..717994b --- /dev/null +++ b/gcc/testsuite/g++.dg/template/conv13.C @@ -0,0 +1,13 @@ +// PR c++/52088 + +struct S +{ + template + operator T *() { return 0; } +}; + +int main() +{ + S s; + delete s; // { dg-error "ambiguous|template|pointer" } +}