From patchwork Thu Sep 19 20:36:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1987572 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=T/WCYPg9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X8nsk29bPz1y2j for ; Fri, 20 Sep 2024 06:58:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 47412385840B for ; Thu, 19 Sep 2024 20:58:00 +0000 (GMT) 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 [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 0A10B3858D29 for ; Thu, 19 Sep 2024 20:57:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0A10B3858D29 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0A10B3858D29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726779462; cv=none; b=ALoozHK8P2YhUlmU2bHiYcHFDpxS0uhOp8PH3nBn4u9nglOTmA5WUxxer65Fq1eFHsAIs1Pwjg3QHcuy5VfzlDsuajzXy/Es/HlCReNIoXxwwU0nmsCilSIjEFWTa4BYmqJA/g82iSuaUzR+I9MAbeF6HHYbufIxifJqeib8ih0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726779462; c=relaxed/simple; bh=Jvc8KdZ1fjdUf3Kvc4FXnzWvtreKGTcUxakei27MG7o=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=h8HBNyhiXiwFlkGff5x4NPZ9ajRaeHkRvzsu7P991ttO1OKnwkibn8VXcufPWxuzriis+Z4X9ynlri8M3NUI5gLNkJaeO1YV0yrqb6lI7eL3rwXgbBgvgejNuofhR1UMzivFIBdFvvHvGtM4XOdnkcjktvW//PBFknvYDsOuW2s= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726779454; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-to:resent-from:resent-message-id; bh=fu1327cZtkF/nW013Hybn+x8Je/PeRVCWuY/2lbQVxI=; b=T/WCYPg9x1AiHOu78c6glrIQPrCvHvc2nRC9NTl5kTU1A0TEXnfNvzNijUEQA/1gKNjXPH ZUPQRJqvX9z2CEtF0dyEfQc9Up6xyUb3br4+3C9cJ8nFfYIW1rn6X9FCgtoHeFbsVcQAgK Rw2x7Ys3oQEj2D9HwBE47mTMYIwocs8= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-261-m-Qe_X1vMSGxYOPRjDqvdw-1; Thu, 19 Sep 2024 16:57:33 -0400 X-MC-Unique: m-Qe_X1vMSGxYOPRjDqvdw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 448C419775F5 for ; Thu, 19 Sep 2024 20:57:32 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.61]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A6B64300208B for ; Thu, 19 Sep 2024 20:57:31 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 48JKvS141840344 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Thu, 19 Sep 2024 22:57:28 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 48JKvSmn1840343 for gcc-patches@gcc.gnu.org; Thu, 19 Sep 2024 22:57:28 +0200 Resent-From: Jakub Jelinek Resent-Date: Thu, 19 Sep 2024 22:57:28 +0200 Resent-Message-ID: Resent-To: gcc-patches@gcc.gnu.org Date: Thu, 19 Sep 2024 22:36:01 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Use type_id_in_expr_sentinel in 6 further spots in the parser Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! The following patch uses type_id_in_expr_sentinel in a few spots which did it all manually. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-09-19 Jakub Jelinek * parser.cc (cp_parser_postfix_expression): Use type_id_in_expr_sentinel instead of manually saving+setting/restoring parser->in_type_id_in_expr_p around cp_parser_type_id calls. (cp_parser_has_attribute_expression): Likewise. (cp_parser_cast_expression): Likewise. (cp_parser_sizeof_operand): Likewise. Jakub --- gcc/cp/parser.cc.jj 2024-09-07 09:31:20.708482757 +0200 +++ gcc/cp/parser.cc 2024-09-19 10:46:21.916155154 +0200 @@ -7554,7 +7554,6 @@ cp_parser_postfix_expression (cp_parser tree type; cp_expr expression; const char *saved_message; - bool saved_in_type_id_in_expr_p; /* All of these can be handled in the same way from the point of view of parsing. Begin by consuming the token @@ -7569,11 +7568,11 @@ cp_parser_postfix_expression (cp_parser /* Look for the opening `<'. */ cp_parser_require (parser, CPP_LESS, RT_LESS); /* Parse the type to which we are casting. */ - saved_in_type_id_in_expr_p = parser->in_type_id_in_expr_p; - parser->in_type_id_in_expr_p = true; - type = cp_parser_type_id (parser, CP_PARSER_FLAGS_TYPENAME_OPTIONAL, - NULL); - parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p; + { + type_id_in_expr_sentinel s (parser); + type = cp_parser_type_id (parser, CP_PARSER_FLAGS_TYPENAME_OPTIONAL, + NULL); + } /* Look for the closing `>'. */ cp_parser_require_end_of_template_parameter_list (parser); /* Restore the old message. */ @@ -7643,7 +7642,6 @@ cp_parser_postfix_expression (cp_parser { tree type; const char *saved_message; - bool saved_in_type_id_in_expr_p; /* Consume the `typeid' token. */ cp_lexer_consume_token (parser->lexer); @@ -7658,10 +7656,10 @@ cp_parser_postfix_expression (cp_parser expression. */ cp_parser_parse_tentatively (parser); /* Try a type-id first. */ - saved_in_type_id_in_expr_p = parser->in_type_id_in_expr_p; - parser->in_type_id_in_expr_p = true; - type = cp_parser_type_id (parser); - parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p; + { + type_id_in_expr_sentinel s (parser); + type = cp_parser_type_id (parser); + } /* Look for the `)' token. Otherwise, we can't be sure that we're not looking at an expression: consider `typeid (int (3))', for example. */ @@ -7916,10 +7914,8 @@ cp_parser_postfix_expression (cp_parser else { /* Parse the type. */ - bool saved_in_type_id_in_expr_p = parser->in_type_id_in_expr_p; - parser->in_type_id_in_expr_p = true; + type_id_in_expr_sentinel s (parser); type = cp_parser_type_id (parser); - parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p; parens.require_close (parser); } @@ -9502,11 +9498,11 @@ cp_parser_has_attribute_expression (cp_p expression. */ cp_parser_parse_tentatively (parser); - bool saved_in_type_id_in_expr_p = parser->in_type_id_in_expr_p; - parser->in_type_id_in_expr_p = true; - /* Look for the type-id. */ - oper = cp_parser_type_id (parser); - parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p; + { + type_id_in_expr_sentinel s (parser); + /* Look for the type-id. */ + oper = cp_parser_type_id (parser); + } cp_parser_parse_definitely (parser); @@ -10268,15 +10264,13 @@ cp_parser_cast_expression (cp_parser *pa cp_parser_simulate_error (parser); else { - bool saved_in_type_id_in_expr_p = parser->in_type_id_in_expr_p; - parser->in_type_id_in_expr_p = true; + type_id_in_expr_sentinel s (parser); /* Look for the type-id. */ type = cp_parser_type_id (parser); /* Look for the closing `)'. */ cp_token *close_paren = parens.require_close (parser); if (close_paren) close_paren_loc = close_paren->location; - parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p; } /* Restore the saved message. */ @@ -34299,13 +34293,11 @@ cp_parser_sizeof_operand (cp_parser* par cp_parser_simulate_error (parser); else { - bool saved_in_type_id_in_expr_p = parser->in_type_id_in_expr_p; - parser->in_type_id_in_expr_p = true; + type_id_in_expr_sentinel s (parser); /* Look for the type-id. */ type = cp_parser_type_id (parser); /* Look for the closing `)'. */ parens.require_close (parser); - parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p; } /* If all went well, then we're done. */