From patchwork Wed Oct 20 21:40:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1544045 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=Xsu0XYmb; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4HZPDQ3yh5z9sR4 for ; Thu, 21 Oct 2021 08:40:37 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 845A43857C75 for ; Wed, 20 Oct 2021 21:40:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 845A43857C75 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1634766034; bh=oeL9zeHIbgd3XiVn/F7o5KlMLoXnz+XSyMSKwmuT+GQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Xsu0XYmb9/6PqpxB/lqR1AnCk3S0f0V8tdtlsAHixCRjMxOKr+BTo8EizaqeINNha hSNfWVv0N33+R39kb6pdtem/W2TGfyNjZstssiroKlaenLpbUFEPSDiecZVj2IoMjF LxLfqQei2AAeyiLIK4aBfImbljB1uuOnPyM05dJY= 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 ESMTPS id 1E5A53858D39 for ; Wed, 20 Oct 2021 21:40:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1E5A53858D39 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-555-vuQ95IpxPECKTxnyaUnA3A-1; Wed, 20 Oct 2021 17:40:12 -0400 X-MC-Unique: vuQ95IpxPECKTxnyaUnA3A-1 Received: by mail-qv1-f69.google.com with SMTP id gw8-20020a0562140f0800b0038366347de1so3867623qvb.16 for ; Wed, 20 Oct 2021 14:40:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=oeL9zeHIbgd3XiVn/F7o5KlMLoXnz+XSyMSKwmuT+GQ=; b=RWdZdO7fshaH+tqr9ecAI2gpeP2Hjn59mFGa1zNR0i9XOrpm4CzKeA+yXdAK7TZ4JE 4D7psp8Oiuwodb3kZRQeRDazMMyM+cJDJft2hXPuQw8Rv6Iyc61c0aQgpYX/D8kdmAPZ OD5nVU5SqXqJPdhee1g9EM3hYmrFfJ/lRxDG3kJUVCpInKonA3VT60NG+ZuIYBzPRB9+ ghREY0igIhr5pLMUQdNme3ka+52y2B9DX+KfIIfBWe/NwyqTl2KtDcpePdJebH3EftVU O8J2TT5qwtgsLynZo6P95ebXtT4MpgHtSvUtlBrt9R7f4qok5QeQx+scEotPKHud6raV 0yhg== X-Gm-Message-State: AOAM530hVciksc9JT45+wQR1TcmJnxGQmMFU9F1trDkNIZhF2xgp9mLL vPI73Th2BSkvXF5SXqS63PPxxL8cifum+GDPoDxL103hThT6ElDm9r3zXA3UZC7irVSkEbuD3ui E0vZOcNXVH0GDjHfteagxN0qlkMqdWK2ZYk7cxzM4z6iSEtq78/gJkTTjoBk1jIL1Rg== X-Received: by 2002:a37:a991:: with SMTP id s139mr1441036qke.356.1634766011798; Wed, 20 Oct 2021 14:40:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxb5W8gmT0pFlVo0bLVrufuOLUu9FNM9mcwGGbt9DetMI3ZQcBGFuAssxn3fuu5NBx1Vgzkag== X-Received: by 2002:a37:a991:: with SMTP id s139mr1441015qke.356.1634766011414; Wed, 20 Oct 2021 14:40:11 -0700 (PDT) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id u185sm1597214qkd.48.2021.10.20.14.40.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 14:40:10 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: tweak parsing of invalid types Date: Wed, 20 Oct 2021 17:40:09 -0400 Message-Id: <20211020214009.962269-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.0 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_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Cc: anthonysharp15@gmail.com Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" cp_parser_parse_and_diagnose_invalid_type_name is called during declaration parsing, so it should pass 'true' for the declarator_p argument. But that caused a diagnostic regression on template/pr84789.C due to undesired lookup in dependent scopes. To fix that, cp_parser_nested_name_specifier_opt needs to respect the value of check_dependency_p. This patch avoids a regression from Andrew Sharp's WIP patch for PR70417. It would make more sense to test only check_dependency_p, not declarator_p, but removing the declarator_p condition turns out to reveal complicated interactions of cp_parser_constructor_declarator_p and caching of nested-name-specifiers and template-ids that I've already spent too much time trying to sort out. Tested x86_64-pc-linux-gnu, applying to trunk. gcc/cp/ChangeLog: * parser.c (cp_parser_parse_and_diagnose_invalid_type_name): Pass true for declarator_p. (cp_parser_nested_name_specifier_opt): Only look through TYPENAME_TYPE if check_dependency_p is false. --- gcc/cp/parser.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) base-commit: 788483f77de04515b0b72d3c4c841c37b005f404 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 9c7ed65f55c..49d951cfb19 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -3693,7 +3693,7 @@ cp_parser_parse_and_diagnose_invalid_type_name (cp_parser *parser) /*template_keyword_p=*/false, /*check_dependency_p=*/true, /*template_p=*/NULL, - /*declarator_p=*/false, + /*declarator_p=*/true, /*optional_p=*/false); /* If the next token is a (, this is a function with no explicit return type, i.e. constructor, destructor or conversion op. */ @@ -6605,6 +6605,8 @@ check_template_keyword_in_nested_name_spec (tree name) it unchanged if there is no nested-name-specifier. Returns the new scope iff there is a nested-name-specifier, or NULL_TREE otherwise. + If CHECK_DEPENDENCY_P is FALSE, names are looked up in dependent scopes. + If IS_DECLARATION is TRUE, the nested-name-specifier is known to be part of a declaration and/or decl-specifier. */ @@ -6645,9 +6647,10 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser, /* Grab the nested-name-specifier and continue the loop. */ cp_parser_pre_parsed_nested_name_specifier (parser); /* If we originally encountered this nested-name-specifier - with IS_DECLARATION set to false, we will not have + with CHECK_DEPENDENCY_P set to true, we will not have resolved TYPENAME_TYPEs, so we must do so here. */ if (is_declaration + && !check_dependency_p && TREE_CODE (parser->scope) == TYPENAME_TYPE) { new_scope = resolve_typename_type (parser->scope, @@ -6729,6 +6732,7 @@ cp_parser_nested_name_specifier_opt (cp_parser *parser, a template. So, if we have a typename at this point, we make an effort to look through it. */ if (is_declaration + && !check_dependency_p && !typename_keyword_p && parser->scope && TREE_CODE (parser->scope) == TYPENAME_TYPE)