From patchwork Tue Sep 4 18:48:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 181653 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 7FD342C008D for ; Wed, 5 Sep 2012 04:48:27 +1000 (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=1347389307; 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=8JGn6DK mbJ/OGF+CsKLYuXcCVlU=; b=ThoNMwuHd/FmBtkcrXZC8GWUhZF1Ufh7L7aCbU9 6CAAL253+cAmbEQUta4t0j6SiTFBYvEvz2MeqE/Lms8t+TBNId+Kexi04w8QmG+f 2lhLeMgmawKpnTYMLVIa7bVNVZJAC5wuAIque1jrfEjFUZjdT4ceRiVjp+XINrB6 5AJs= 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=bjNiAAd6qykAtp+NRZrAnbKeazgMmlWEnu+aRdKjewWEbCaWJvRAUNk9umofnC MdCxof/ihXpY+xK2njhxNP6v5X2vB7Y8IuyTtL4eAJepisVcjC2l9L1+SLzvgoKI Ja4EMWUimEtHkTxmwFUaa2dRa21joHjwpFKQGA7oCF22A=; Received: (qmail 26392 invoked by alias); 4 Sep 2012 18:48:20 -0000 Received: (qmail 26171 invoked by uid 22791); 4 Sep 2012 18:48:18 -0000 X-SWARE-Spam-Status: No, hits=-6.4 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_FN 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; Tue, 04 Sep 2012 18:48:02 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q84Im2d9021522 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 4 Sep 2012 14:48:02 -0400 Received: from [10.3.113.46] (ovpn-113-46.phx2.redhat.com [10.3.113.46]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q84Im1xF021190 for ; Tue, 4 Sep 2012 14:48:02 -0400 Message-ID: <50464CE1.4090904@redhat.com> Date: Tue, 04 Sep 2012 14:48:01 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120828 Thunderbird/15.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/54437 (firefox build failure) 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 Here, the problem was that we were resolving the address of an overloaded function in the context of the template being called (which doesn't have access to the function) rather than the caller (which does). We need to massage explicit template arguments before we enter the callee's context. Tested x86_64-pc-linux-gnu, applying to trunk. commit c17767b10d05c0ea47107a3b7f067da76cc5ad8d Author: Jason Merrill Date: Tue Sep 4 11:27:03 2012 -0400 PR c++/54437 PR c++/51213 * pt.c (fn_type_unification): Call coerce_template_parms before entering substitution context. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 4a39427..6f6235c 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -14591,11 +14591,22 @@ fn_type_unification (tree fn, static int deduction_depth; struct pending_template *old_last_pend = last_pending_template; struct tinst_level *old_error_tinst = last_error_tinst_level; + tree tparms = DECL_INNERMOST_TEMPLATE_PARMS (fn); tree tinst; tree r = error_mark_node; - if (excessive_deduction_depth) - return error_mark_node; + /* Adjust any explicit template arguments before entering the + substitution context. */ + if (explicit_targs) + { + explicit_targs + = (coerce_template_parms (tparms, explicit_targs, NULL_TREE, + complain, + /*require_all_args=*/false, + /*use_default_args=*/false)); + if (explicit_targs == error_mark_node) + return error_mark_node; + } /* In C++0x, it's possible to have a function template whose type depends on itself recursively. This is most obvious with decltype, but can also @@ -14608,6 +14619,8 @@ fn_type_unification (tree fn, substitutions back up to the initial one. This is, of course, not reentrant. */ + if (excessive_deduction_depth) + return error_mark_node; tinst = build_tree_list (fn, targs); if (!push_tinst_level (tinst)) { @@ -14640,23 +14653,10 @@ fn_type_unification (tree fn, specified template argument values. If a substitution in a template parameter or in the function type of the function template results in an invalid type, type deduction fails. */ - tree tparms = DECL_INNERMOST_TEMPLATE_PARMS (fn); int i, len = TREE_VEC_LENGTH (tparms); location_t loc = input_location; - tree converted_args; bool incomplete = false; - if (explicit_targs == error_mark_node) - goto fail; - - converted_args - = (coerce_template_parms (tparms, explicit_targs, NULL_TREE, - complain, - /*require_all_args=*/false, - /*use_default_args=*/false)); - if (converted_args == error_mark_node) - goto fail; - /* Substitute the explicit args into the function type. This is necessary so that, for instance, explicitly declared function arguments can match null pointed constants. If we were given @@ -14667,7 +14667,7 @@ fn_type_unification (tree fn, { tree parm = TREE_VALUE (TREE_VEC_ELT (tparms, i)); bool parameter_pack = false; - tree targ = TREE_VEC_ELT (converted_args, i); + tree targ = TREE_VEC_ELT (explicit_targs, i); /* Dig out the actual parm. */ if (TREE_CODE (parm) == TYPE_DECL @@ -14705,7 +14705,7 @@ fn_type_unification (tree fn, processing_template_decl += incomplete; input_location = DECL_SOURCE_LOCATION (fn); - fntype = tsubst (TREE_TYPE (fn), converted_args, + fntype = tsubst (TREE_TYPE (fn), explicit_targs, complain | tf_partial, NULL_TREE); input_location = loc; processing_template_decl -= incomplete; @@ -14714,8 +14714,8 @@ fn_type_unification (tree fn, goto fail; /* Place the explicitly specified arguments in TARGS. */ - for (i = NUM_TMPL_ARGS (converted_args); i--;) - TREE_VEC_ELT (targs, i) = TREE_VEC_ELT (converted_args, i); + for (i = NUM_TMPL_ARGS (explicit_targs); i--;) + TREE_VEC_ELT (targs, i) = TREE_VEC_ELT (explicit_targs, i); } /* Never do unification on the 'this' parameter. */ diff --git a/gcc/testsuite/g++.dg/template/access24.C b/gcc/testsuite/g++.dg/template/access24.C new file mode 100644 index 0000000..9f19226 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/access24.C @@ -0,0 +1,8 @@ +// PR c++/54437 + +template void f(); +class A { + template static void g(); + template static void h () { f >(); } + static void i() { h(); } +};