From patchwork Thu Aug 15 20:53:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1972952 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=FoS8TJiQ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WlHRM5V0rz1yXZ for ; Fri, 16 Aug 2024 06:54:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 966E8385DDC1 for ; Thu, 15 Aug 2024 20:54:05 +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 3A1B53858404 for ; Thu, 15 Aug 2024 20:53:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3A1B53858404 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 3A1B53858404 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=1723755221; cv=none; b=trWk7CRjC5LTqC6hvz8z9yya2kCI0RyyJk7Suhy8ZscLrWWugtGzsv5v9F5qavg7EKVdnWHwmibc9OyU8L8cIYE4XS1YPJOT1oRG4whBj5VPSUj8/QcMOVCKUqot+Fq+dFFuegQytylfuXNDSAfkCYGUgQN1mErLO3OPg89c8d0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723755221; c=relaxed/simple; bh=S5+JEam/aDrFM/JnUcfi6pqErQlfaIXj/roKXeb60HM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=mFaNK5X7dzahIV+QdKJf7b8NpfrTq0dDKnVnW3Bko9NOWIVQHnlsgKgyklWAiDnuZi9Wc3UxtcaXIStH2bHo888BePymd/G/DTgKRrj3qbfuOCLLLdowpMKsIehFwrMNkDjm2ahC8DIUcJG0DKRWa6J+Ub4RsV8S9BcHcix66I8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723755219; 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; bh=rp/LUXCnrvcN879gf/qxpU6jYgzu7qKiE1HCVsyxxyU=; b=FoS8TJiQ7XpXgbe2IAtO21SwjxVHNohBrbzkyPOoj+LgtA6Wt9TwAkKiUrtZqfZg7132Ow kCowpIlSjbLjXjqiG2YsbOEZ30CQY0ETYMvcsPEX7MQwZGdFnFiBu4jbPO+jBdoBxqGKul 5nq3eoONy/042+c+jf7zg4HRvP4tkRQ= Received: from mx-prod-mc-03.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-695-dpRjw2fEN_WSYIlcKcLRwA-1; Thu, 15 Aug 2024 16:53:37 -0400 X-MC-Unique: dpRjw2fEN_WSYIlcKcLRwA-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1F42F19560B4 for ; Thu, 15 Aug 2024 20:53:37 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.8]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 93E3319560AA; Thu, 15 Aug 2024 20:53:36 +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 47FKrXfW3512281 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 15 Aug 2024 22:53:33 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 47FKrXNI3512280; Thu, 15 Aug 2024 22:53:33 +0200 Date: Thu, 15 Aug 2024 22:53:33 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Parse and ignore attributes on base specifiers [PR110345] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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! For C++ 26 P2552R3 I went through all the spots (except modules) where attribute-specifier-seq appears in the grammar and tried to construct a testcase in all those spots, for now for [[deprecated]] attribute. This is the third issue I found. https://eel.is/c++draft/class.derived#general-1 has attribute-specifier-seq at the start of base-specifier. The following patch parses it there and warns about those. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-08-15 Jakub Jelinek PR c++/110345 * parser.cc (cp_parser_base_specifier): Parse standard attributes at the start and emit a warning if there are any non-ignored ones. * g++.dg/cpp0x/gen-attrs-83.C: New test. Jakub --- gcc/cp/parser.cc.jj 2024-08-15 17:41:44.554159692 +0200 +++ gcc/cp/parser.cc 2024-08-15 18:00:33.202211372 +0200 @@ -28987,11 +28987,12 @@ cp_parser_base_clause (cp_parser* parser /* Parse a base-specifier. base-specifier: - :: [opt] nested-name-specifier [opt] class-name - virtual access-specifier [opt] :: [opt] nested-name-specifier - [opt] class-name - access-specifier virtual [opt] :: [opt] nested-name-specifier - [opt] class-name + attribute-specifier-seq [opt] :: [opt] nested-name-specifier [opt] + class-name + attribute-specifier-seq [opt] virtual access-specifier [opt] :: [opt] + nested-name-specifier [opt] class-name + attribute-specifier-seq [opt] access-specifier virtual [opt] :: [opt] + nested-name-specifier [opt] class-name Returns a TREE_LIST. The TREE_PURPOSE will be one of ACCESS_{DEFAULT,PUBLIC,PROTECTED,PRIVATE}_[VIRTUAL]_NODE to @@ -29009,6 +29010,12 @@ cp_parser_base_specifier (cp_parser* par bool class_scope_p, template_p; tree access = access_default_node; tree type; + location_t attrs_loc = cp_lexer_peek_token (parser->lexer)->location; + tree std_attrs = cp_parser_std_attribute_spec_seq (parser); + + if (std_attrs != NULL_TREE && any_nonignored_attribute_p (std_attrs)) + warning_at (attrs_loc, OPT_Wattributes, + "attributes on base specifiers are ignored"); /* Process the optional `virtual' and `access-specifier'. */ while (!done) --- gcc/testsuite/g++.dg/cpp0x/gen-attrs-83.C.jj 2024-08-15 17:58:52.093456428 +0200 +++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-83.C 2024-08-15 18:27:23.864431390 +0200 @@ -0,0 +1,10 @@ +// { dg-do compile { target c++11 } } + +struct A {}; +struct B {}; +struct C {}; +struct D : [[]] [[]] A, + [[]] virtual public B, [[]] [[]] [[]] public virtual C {}; +struct E : [[gnu::deprecated]] A, // { dg-warning "attributes on base specifiers are ignored" } + [[gnu::deprecated]] virtual public B, // { dg-warning "attributes on base specifiers are ignored" } + [[gnu::deprecated]] public virtual C {}; // { dg-warning "attributes on base specifiers are ignored" }