From patchwork Fri Feb 13 16:02:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 439523 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7D8731402EB for ; Sat, 14 Feb 2015 03:02:26 +1100 (AEDT) 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=FjuoR2wGRdYkTZWoaBbONoY1tijcBt+4o71BQiIEYyIM5w Dv3AjkvVdAdmdUfpZ+WFgxS0J4hY34fPaoTAyRd4FUFfbKS4d3kvWVKiv9SPHFOD ys3ucyE48x0KdsXSrHXWIqfVTfVA34sx9JNtrJ76SEbA6aOtD4AipFwDEgOp0= 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=nEFGLCbhEugBsPkVVLZTTicKyDk=; b=LNb7JujeDBqYTyyZ479s a6KKGUggRYKxiTdZQOvvZE/zZi+FtDJ3p2hCtzCbMmJORkRWw5uy2Xqy5T+owgok 8fHWhvi4pKmCLL/l+Dken9LXMveFLCRVpzNmRjAggbCfyczOL327iPga9TwKQPNc eXUhQ6Y3UijDGmjhHHQ/OoY= Received: (qmail 21950 invoked by alias); 13 Feb 2015 16:02:18 -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 21938 invoked by uid 89); 13 Feb 2015 16:02:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 13 Feb 2015 16:02:15 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1DG2EDu022299 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 13 Feb 2015 11:02:14 -0500 Received: from [10.10.116.30] ([10.10.116.30]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t1DG2Dol012167 for ; Fri, 13 Feb 2015 11:02:13 -0500 Message-ID: <54DE2002.1070301@redhat.com> Date: Fri, 13 Feb 2015 11:02:10 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/65051 (wrong template instantiation in overload resolution) My patch to make the compiler give more friendly diagnostics about cv-qual dropping in reference binding meant that we looked for conversions to incomplete class type, leading to instantiating that type, which can lead to errors that would not otherwise occur. So don't try if the target is incomplete. Tested x86_64-pc-linux-gnu, applying to trunk. commit c16cd1efe8d627fab1e03a0278ea974edc3d947f Author: Jason Merrill Date: Fri Feb 13 10:17:02 2015 -0500 PR c++/65051 * call.c (reference_binding): Don't look for bad conversion if TO is incomplete. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index f2076c6..2b15185 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -1694,6 +1694,19 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags, difference in top-level cv-qualification is subsumed by the initialization itself and does not constitute a conversion. */ + /* [dcl.init.ref] + + Otherwise, the reference shall be an lvalue reference to a + non-volatile const type, or the reference shall be an rvalue + reference. + + We try below to treat this as a bad conversion to improve diagnostics, + but if TO is an incomplete class, we need to reject this conversion + now to avoid unnecessary instantiation. */ + if (!CP_TYPE_CONST_NON_VOLATILE_P (to) && !TYPE_REF_IS_RVALUE (rto) + && !COMPLETE_TYPE_P (to)) + return NULL; + /* We're generating a temporary now, but don't bind any more in the conversion (specifically, don't slice the temporary returned by a conversion operator). */ diff --git a/gcc/testsuite/g++.dg/template/overload14.C b/gcc/testsuite/g++.dg/template/overload14.C new file mode 100644 index 0000000..ec2c381 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/overload14.C @@ -0,0 +1,18 @@ +// PR c++/65051 + +template struct wrap { typedef T type; }; +template class rv: public wrap ::type {}; + +template +struct circular_buffer +{ + typedef const value_type& param_value_type; + typedef rv< value_type >& rvalue_type; + + void push_back(param_value_type item) {} + void push_back(rvalue_type item) {} +}; + +union U { int i; char c; }; + +void f(circular_buffer b, const U& u) { b.push_back(u); }