From patchwork Tue Jul 16 08:49:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1132528 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-505121-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="hNEJAbWz"; dkim-atps=neutral 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 45nvH51Hyqz9sN4 for ; Tue, 16 Jul 2019 18:50:08 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version :content-transfer-encoding; q=dns; s=default; b=JV12vJDw4qy1T7ft 9Ir3doY5HZvz6tc4wqvGB3cycgs4RQO1syfn0Vn5R0eHoJfkwdywPMzlbahsFz5q /+kUfqjE8Yfe+vTJDHK+BLBMNqRiC12E84ExSpL/tmgpjRIr2iwDrWXSAmjLjaNn rxogl8KylRMPZtYLGGNuh7Ogfbs= 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:from :to:subject:date:message-id:mime-version :content-transfer-encoding; s=default; bh=lvEhJ4C+gSDiy/py16CXVO UWhJg=; b=hNEJAbWzYisHVXWyzCGyLbgMCmB4ipMOrINcR/p64tEgT49LdpY+Nv VP7Qa1tR8OczNXWUFLZxitxS6/VjZQdhBdaDx5jaI3V4EHi5m7HvBB9wZycIwl6h VwXEoNg4iNp3yI2k5viAA6na7RFbiPcCTWqo6InJcT8ArjcjLFjQw= Received: (qmail 117697 invoked by alias); 16 Jul 2019 08:50:01 -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 117683 invoked by uid 89); 16 Jul 2019 08:50:01 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=HX-Received:sk:f15mr33, HContent-Transfer-Encoding:8bit X-HELO: mail-wr1-f45.google.com Received: from mail-wr1-f45.google.com (HELO mail-wr1-f45.google.com) (209.85.221.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 16 Jul 2019 08:50:00 +0000 Received: by mail-wr1-f45.google.com with SMTP id c2so16786229wrm.8 for ; Tue, 16 Jul 2019 01:49:59 -0700 (PDT) Received: from localhost.localdomain ([62.153.214.124]) by smtp.gmail.com with ESMTPSA id t185sm13884909wma.11.2019.07.16.01.49.56 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 16 Jul 2019 01:49:56 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Simplify type-specifier parsing. Date: Tue, 16 Jul 2019 10:49:48 +0200 Message-Id: <20190716084948.627-1-jason@redhat.com> MIME-Version: 1.0 X-IsSubscribed: yes Previously, the tentative parses for optional type-specifier and to support class template argument deduction were combined awkwardly. This reorganization was motivated by type-constraint parsing on the new concepts branch. Tested x86_64-pc-linux-gnu, applying to trunk. * parser.c (cp_parser_simple_type_specifier): Separate tentative parses for optional type-spec and CTAD. --- gcc/cp/parser.c | 57 ++++++++++++++++++++++++------------------------ gcc/cp/ChangeLog | 3 +++ 2 files changed, 31 insertions(+), 29 deletions(-) base-commit: ae08adfad0f5fbef575734ce25c9feb3dca3cdac diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 14a2168eb6d..5e4b45391d5 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -17833,7 +17833,7 @@ cp_parser_simple_type_specifier (cp_parser* parser, /* Don't gobble tokens or issue error messages if this is an optional type-specifier. */ - if ((flags & CP_PARSER_FLAGS_OPTIONAL) || cxx_dialect >= cxx17) + if (flags & CP_PARSER_FLAGS_OPTIONAL) cp_parser_parse_tentatively (parser); token = cp_lexer_peek_token (parser->lexer); @@ -17873,37 +17873,26 @@ cp_parser_simple_type_specifier (cp_parser* parser, else { cp_parser_error (parser, "expected template-id for type"); - type = NULL_TREE; + type = error_mark_node; } } } - /* Otherwise, look for a type-name. */ - else - type = cp_parser_type_name (parser, (qualified_p && typename_p)); - /* Keep track of all name-lookups performed in class scopes. */ - if (type - && !global_p - && !qualified_p - && TREE_CODE (type) == TYPE_DECL - && identifier_p (DECL_NAME (type))) - maybe_note_name_used_in_class (DECL_NAME (type), type); - /* If it didn't work out, we don't have a TYPE. */ - if (((flags & CP_PARSER_FLAGS_OPTIONAL) || cxx_dialect >= cxx17) - && !cp_parser_parse_definitely (parser)) - type = NULL_TREE; - if (!type && cxx_dialect >= cxx17) + /* Otherwise, look for a type-name. */ + if (!type) { - if (flags & CP_PARSER_FLAGS_OPTIONAL) + if (cxx_dialect >= cxx17) cp_parser_parse_tentatively (parser); - cp_parser_global_scope_opt (parser, - /*current_scope_valid_p=*/false); - cp_parser_nested_name_specifier_opt (parser, - /*typename_keyword_p=*/false, - /*check_dependency_p=*/true, - /*type_p=*/false, - /*is_declaration=*/false); + type = cp_parser_type_name (parser, (qualified_p && typename_p)); + + if (cxx_dialect >= cxx17 && !cp_parser_parse_definitely (parser)) + type = NULL_TREE; + } + + if (!type && cxx_dialect >= cxx17) + { + /* Try class template argument deduction. */ tree name = cp_parser_identifier (parser); if (name && TREE_CODE (name) == IDENTIFIER_NODE && parser->scope != error_mark_node) @@ -17929,11 +17918,21 @@ cp_parser_simple_type_specifier (cp_parser* parser, } else type = error_mark_node; - - if ((flags & CP_PARSER_FLAGS_OPTIONAL) - && !cp_parser_parse_definitely (parser)) - type = NULL_TREE; } + + /* If it didn't work out, we don't have a TYPE. */ + if ((flags & CP_PARSER_FLAGS_OPTIONAL) + && !cp_parser_parse_definitely (parser)) + type = NULL_TREE; + + /* Keep track of all name-lookups performed in class scopes. */ + if (type + && !global_p + && !qualified_p + && TREE_CODE (type) == TYPE_DECL + && identifier_p (DECL_NAME (type))) + maybe_note_name_used_in_class (DECL_NAME (type), type); + if (type && decl_specs) cp_parser_set_decl_spec_type (decl_specs, type, token, diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index bd85c705629..ad7f4a3ae1f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2019-07-16 Jason Merrill + * parser.c (cp_parser_simple_type_specifier): Separate tentative + parses for optional type-spec and CTAD. + * parser.c (cp_parser_nested_name_specifier_opt): If the token is already CPP_NESTED_NAME_SPECIFIER, leave it alone.