From patchwork Mon Oct 5 23:07:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1377169 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Pb6+P+ig; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C4x8204Yhz9sS8 for ; Tue, 6 Oct 2020 10:07:30 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 61A0F3857C50; Mon, 5 Oct 2020 23:07:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61A0F3857C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1601939247; bh=IfeOaD4PoLGw58w+4l9g3JosPehQPSi1xBjGQdbrRWc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Pb6+P+ig8sUUcLXsruYWFhP4Xp2m0n4uNzvmpVMVBX4v/0VOSkHgFshvZWaYd6aA3 67UIWOuvCoXiuYTyGLlTIOvoU9PPnkaPNVNRb1YasvuRQngy8Q5URM2qZx36bqzaJA CLIH7wWqQ2iclGhX3HvPK9YYCzZAvlbQyjNV5mqI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 4DD2F3857C4E for ; Mon, 5 Oct 2020 23:07:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4DD2F3857C4E Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-315-llEkSKMqOAaiKJZJgoCZwQ-1; Mon, 05 Oct 2020 19:07:21 -0400 X-MC-Unique: llEkSKMqOAaiKJZJgoCZwQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E5B491DE07 for ; Mon, 5 Oct 2020 23:07:20 +0000 (UTC) Received: from pdp-11.redhat.com (ovpn-119-216.rdu2.redhat.com [10.10.119.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A5BD78807; Mon, 5 Oct 2020 23:07:20 +0000 (UTC) To: GCC Patches , Jason Merrill Subject: [PATCH] c++: typename in out-of-class member function definitions [PR97297] Date: Mon, 5 Oct 2020 19:07:12 -0400 Message-Id: <20201005230712.3830459-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" I was notified that our P0634R3 (Down with typename) implementation has a flaw: when we have an out-of-class member function definition, we still required 'typename' for its parameters. For example here: template struct S { int simple(T::type); }; template int S::simple(/* typename */T::type) { return 0; } the 'typename' isn't necessary per [temp.res]/5.2.4. We have a qualified name here ("S::simple") so we know it's already been declared so we can look it up to see if it's a function template or a variable template. In this case, the P0634R3 code in cp_parser_direct_declarator wasn't looking into uninstantiated templates and didn't find the member function 'simple' -- cp_parser_lookup_name returned a SCOPE_REF which means that the qualifying scope was dependent. With this fix, we find the BASELINK for 'simple', don't clear CP_PARSER_FLAGS_TYPENAME_OPTIONAL from the flags, and the typename is implicitly assumed. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? gcc/cp/ChangeLog: PR c++/97297 * parser.c (cp_parser_direct_declarator): When checking if a name is a function template declaration for the P0634R3 case, look in uninstantiated templates too. gcc/testsuite/ChangeLog: PR c++/97297 * g++.dg/cpp2a/typename18.C: New test. --- gcc/cp/parser.c | 10 ++++++++-- gcc/testsuite/g++.dg/cpp2a/typename18.C | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/typename18.C base-commit: ea6da7f50fe2adc3a09fc10a3f437902c40ebff9 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index cb4422764ed..2002c05fdb5 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -21788,8 +21788,14 @@ cp_parser_direct_declarator (cp_parser* parser, templates, assume S::p to name a type. Otherwise, don't. */ tree decl - = cp_parser_lookup_name_simple (parser, unqualified_name, - token->location); + = cp_parser_lookup_name (parser, unqualified_name, + none_type, + /*is_template=*/false, + /*is_namespace=*/false, + /*check_dependency=*/false, + /*ambiguous_decls=*/NULL, + token->location); + if (!is_overloaded_fn (decl) /* Allow template diff --git a/gcc/testsuite/g++.dg/cpp2a/typename18.C b/gcc/testsuite/g++.dg/cpp2a/typename18.C new file mode 100644 index 00000000000..99468661491 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/typename18.C @@ -0,0 +1,21 @@ +// PR c++/97297 +// { dg-do compile { target c++20 } } + +template +struct S { + int simple(T::type); + + template + int member(U::type); +}; + +template +int S::simple(T::type) { + return 1; +} + +template +template +int S::member(U::type) { + return 2; +}