From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 112614 invoked by alias); 29 Nov 2018 18:28:25 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 112603 invoked by uid 89); 29 Nov 2018 18:28:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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 ESMTP; Thu, 29 Nov 2018 18:28:22 +0000 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 280883002DA4 for ; Thu, 29 Nov 2018 18:28:21 +0000 (UTC) Received: from redhat.com (ovpn-125-91.rdu2.redhat.com [10.10.125.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ACA9E2633E; Thu, 29 Nov 2018 18:28:20 +0000 (UTC) Date: Thu, 29 Nov 2018 18:28:00 -0000 From: Marek Polacek To: Jason Merrill Cc: GCC Patches Subject: Re: C++ PATCH for c++/88184, ICE when treating name as template-name Message-ID: <20181129182828.GH3269@redhat.com> References: <20181128154849.GD3269@redhat.com> <51f04722-f35d-7df0-40a3-dc7926c82981@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <51f04722-f35d-7df0-40a3-dc7926c82981@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-SW-Source: 2018-11/txt/msg02484.txt.bz2 On Wed, Nov 28, 2018 at 10:34:11PM -0500, Jason Merrill wrote: > On 11/28/18 10:48 AM, Marek Polacek wrote: > > Since P0846R0 was implemented, a name will be treated as a template-name when > > it is an unqualified-id followed by a < and name lookup finds either one or > > more functions or finds nothing, in order to potentially cause ADL to be performed. > > > > In this case, we had > > > > f (); > > > > where we'd found a decl for f (not a TEMPLATE_DECL) and < follows. > > From the backtrace in the PR, it seems as though we're treating f as > non-dependent, which is wrong. type_dependent_expression_p only looks at > the arguments of a TEMPLATE_ID_EXPR if it has unknown_type_node, so we > probably want to give it that type. That was my first attempt but it was crashing everywhere, so I abandoned it. But I was setting unknown_type_node in cp_parser_template_name whereas this patch sets it in cp_parser_postfix_expression, which works and is arguably better because it reuses the diagnostic in finish_call_expr. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2018-11-29 Marek Polacek PR c++/88184, ICE when treating name as template-name. * parser.c (cp_parser_postfix_expression): Set the function decl type to unknown type when the name-as-template-name doesn't have any arguments. * g++.dg/cpp2a/fn-template17.C: New test. * g++.dg/cpp2a/fn-template18.C: New test. diff --git gcc/cp/parser.c gcc/cp/parser.c index 3ef1eda4518..fc328c28f69 100644 --- gcc/cp/parser.c +++ gcc/cp/parser.c @@ -7241,6 +7241,20 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p, complain); } } + else if (TREE_CODE (postfix_expression) == TEMPLATE_ID_EXPR + && (TREE_CODE (TREE_OPERAND (postfix_expression, 0)) + == FUNCTION_DECL) + && args->is_empty ()) + { + /* We can get here when treating a name as a template name + (because it was an unqualified-id followed by a < and + name lookup found a decl), but now we see that there + are no arguments, so ADL isn't possible. Tweak the type + so that the TEMPLATE_ID_EXPR is type-dependent and we get + proper diagnostic down in finish_call_expr. */ + TREE_TYPE (TREE_OPERAND (postfix_expression, 0)) + = unknown_type_node; + } } if (TREE_CODE (postfix_expression) == COMPONENT_REF) diff --git gcc/testsuite/g++.dg/cpp2a/fn-template17.C gcc/testsuite/g++.dg/cpp2a/fn-template17.C new file mode 100644 index 00000000000..f0d24107682 --- /dev/null +++ gcc/testsuite/g++.dg/cpp2a/fn-template17.C @@ -0,0 +1,21 @@ +// PR c++/88184 +// { dg-do compile } +// { dg-options "-std=c++2a -fchecking=2" } + +namespace A +{ + void f (); +} + +using A::f; + +template void g () +{ + f (); // { dg-error "no matching function for call" } +} + +void +fn () +{ + g(); +} diff --git gcc/testsuite/g++.dg/cpp2a/fn-template18.C gcc/testsuite/g++.dg/cpp2a/fn-template18.C new file mode 100644 index 00000000000..7fe5e89ace3 --- /dev/null +++ gcc/testsuite/g++.dg/cpp2a/fn-template18.C @@ -0,0 +1,23 @@ +// PR c++/88184 +// { dg-do compile } +// { dg-options "-std=c++2a -fchecking=2" } + +namespace A +{ + void f (); + void f (int); + void f (int, int); +} + +using A::f; + +template void g () +{ + f (); // { dg-error "no matching function for call" } +} + +void +fn () +{ + g(); +}