From patchwork Thu Aug 15 20:53:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1972951 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=Fhr77pqb; 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 4WlHR0570rz1yXZ for ; Fri, 16 Aug 2024 06:53:48 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8ACE03858404 for ; Thu, 15 Aug 2024 20:53:46 +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 61D4A3858435 for ; Thu, 15 Aug 2024 20:53:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 61D4A3858435 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 61D4A3858435 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=1723755199; cv=none; b=i9GeApolEI7iF5WmVhkJBu34gYdK+gQnE6THAS2M+dQ1oDd+csma+2mcCk2Dap9PyMIj7w4wTfIHk6RbczFlBI0bYujdVmhjzQcRCGDbgG075B7XmR7WZh21WLVKNVzOG9AQBkWB3jVmhZvkIUj/g5gkxBjyTtj8b+gcvmvbbiU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723755199; c=relaxed/simple; bh=xzIEfQR97ZtOc51KsQ0+8GZvA7kn0mQpS2biRmr/VP4=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=vSB5CUkeUPqZjXkZZMIgjE56xjFi2OA2WsMUUQXFmyyQlVXDDU5kNwPPlcvK3Iv7L5XJ0NPBz23LYV86uqT3GZZm0YLcFWQ7Izkxmsrq+MICBQWJeGyq6rBb+b9tJRbw/pKbRg7JRv1XQq4nbbbF0bzmPBCe/9BJHq3YeORAq48= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723755197; 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=iM3Q6HtC2q/YgBTStjk7+5yMHliEN9Oe/0vubhaPZMQ=; b=Fhr77pqbjZVHKOimQ+Nff+TlGymVxYVb1a1ZN/vzpkaIyesyJSYE6/OirpTiS36EBD95ff 31AkO+Id+GK/wKumET8bMOniQfabT0iIQXnITZ+8gEw46ePXZTk5KNH9CQPf8+P8x+Ob/E Yw73TdSNJoU8HQcaF/Haeh6Elszewqc= 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-17-2mL5ybEUOk2gOPMrtt56Yw-1; Thu, 15 Aug 2024 16:53:15 -0400 X-MC-Unique: 2mL5ybEUOk2gOPMrtt56Yw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [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 BF2BE1955BF6 for ; Thu, 15 Aug 2024 20:53:14 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.8]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 30DB8300019A; Thu, 15 Aug 2024 20:53:12 +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 47FKr9xc3512264 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 15 Aug 2024 22:53:10 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 47FKr9FU3512263; Thu, 15 Aug 2024 22:53:09 +0200 Date: Thu, 15 Aug 2024 22:53:09 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Appertain standard attributes after array closing square bracket to array type rather than declarator [PR110345] 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.6 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, 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 second issue I found. The comment already correctly says that attributes after closing ] appertain to the array type, but we were appending them to returned_attrs, so effectively applying them to the declarator (as if they appeared right after declarator-id). Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-08-15 Jakub Jelinek PR c++/110345 * decl.cc (grokdeclarator): Apply declarator->std_attributes for cdk_array to type, rather than chaining it to returned_attrs. * g++.dg/cpp0x/gen-attrs-82.C: New test. * g++.dg/gomp/attrs-3.C (foo): Expect different diagnostics for omp::directive attribute after closing square bracket of an automatic declaration and add a test with the attribute after array's declarator-id. Jakub --- gcc/cp/decl.cc.jj 2024-08-14 18:19:28.000000000 +0200 +++ gcc/cp/decl.cc 2024-08-15 17:06:22.936426690 +0200 @@ -13317,9 +13317,8 @@ grokdeclarator (const cp_declarator *dec /* [dcl.array]/1: The optional attribute-specifier-seq appertains to the - array. */ - returned_attrs = attr_chainon (returned_attrs, - declarator->std_attributes); + array type. */ + decl_attributes (&type, declarator->std_attributes, 0); break; case cdk_function: --- gcc/testsuite/g++.dg/cpp0x/gen-attrs-82.C.jj 2024-08-15 17:15:47.982435384 +0200 +++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-82.C 2024-08-15 17:16:17.112074964 +0200 @@ -0,0 +1,4 @@ +// { dg-do compile { target c++11 } } + +int a [[gnu::common]] [2]; +int b[2] [[gnu::common]]; // { dg-warning "'common' attribute does not apply to types" } --- gcc/testsuite/g++.dg/gomp/attrs-3.C.jj 2023-09-18 10:37:49.710048827 +0200 +++ gcc/testsuite/g++.dg/gomp/attrs-3.C 2024-08-15 22:33:44.570617103 +0200 @@ -35,6 +35,7 @@ foo () int *[[omp::directive (threadprivate (t3))]] c; // { dg-warning "'omp::directive' scoped attribute directive ignored" } int &[[omp::directive (threadprivate (t4))]] d = b; // { dg-warning "'omp::directive' scoped attribute directive ignored" } typedef int T [[omp::directive (threadprivate (t5))]]; // { dg-error "'omp::directive' not allowed to be specified in this context" } - int e[10] [[omp::directive (threadprivate (t6))]]; // { dg-error "'omp::directive' not allowed to be specified in this context" } + int e [[omp::directive (threadprivate (t6))]] [10]; // { dg-error "'omp::directive' not allowed to be specified in this context" } + int f[10] [[omp::directive (threadprivate (t6))]]; // { dg-warning "'omp::directive' scoped attribute directive ignored" } struct [[omp::directive (threadprivate (t7))]] S {}; // { dg-error "'omp::directive' not allowed to be specified in this context" } }