From patchwork Fri Aug 30 17:29:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1979170 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=fXOkSRCt; 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 4WwQBK0Dzbz1yfn for ; Sat, 31 Aug 2024 03:29:28 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B0A6C386183D for ; Fri, 30 Aug 2024 17:29:26 +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 BDCAB3858435 for ; Fri, 30 Aug 2024 17:29:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BDCAB3858435 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 BDCAB3858435 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=1725038949; cv=none; b=aqA8hhL6j1q1zu8QKD5k6O0SoNYFT0GuN1jNA3bBzGMMMTVX/g48oO0SvKY1aOIb77n1jrSOFOPBcDPhWlKa67AQg2WAGFNUFpQpdyMwbGqqH5KRzill8hwiuentwUO9oXyDTmlenUn/kaiFU4UteMn3RgxRmQLfVIl9hOyHVMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725038949; c=relaxed/simple; bh=/VaTPjJx8jsfTZPbJTvMXzmBoZ0XgPpX7JaaSzGq0sA=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=pwatXeZdmbL3H7iUiBKZxLDd6uKYsHJQS52api2Ek/qlKuhrjkh4v4C0ZPXTwfUEjz/xc1tETNUzoaWJZMtzgF7CFKgweGRZseP7hemlOdyIPhLdFMCh/MPjPsPinZVhAvAP4xMso+xn/zkNIqlz86p1lTkJcoMcormqqJqoAxs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725038947; 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=1GQRkBGKHezmXuNVU1qb7rbhI9KyquKzBaLy3BwKK98=; b=fXOkSRCtfDRxSNYJQ95Yutn+9JwPN0/fFNQBDwJ5MCJgGc0qLkC03/CMNGF71Bhrx9VIME Iw2oJoSxG1ogCyqXzLJ+mSV3BtxFcbCWRrfpoRADBz56239qJyMdJ9epJO/nl0Hng+1p5q EZzk4o+Ndet+7C9GkKLaxnvERVfyP5U= Received: from mx-prod-mc-05.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-283-Wyx-UlmPO-W6jfxrfRqL1w-1; Fri, 30 Aug 2024 13:29:05 -0400 X-MC-Unique: Wyx-UlmPO-W6jfxrfRqL1w-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CB34319560A6 for ; Fri, 30 Aug 2024 17:29:04 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.29]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4A17F19560A3; Fri, 30 Aug 2024 17:29:04 +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 47UHT1DA1737845 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 30 Aug 2024 19:29:01 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 47UHT1XC1737844; Fri, 30 Aug 2024 19:29:01 +0200 Date: Fri, 30 Aug 2024 19:29:00 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Handle enum attributes like class attributes [PR110345] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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! As the following testcase shows, cp_parser_decl_specifier_seq was calling warn_misplaced_attr_for_class_type only for class types and not for enum types, while check_tag_decl calls them for both class and enum types. Enum types are really the same case here, the attribute needs to go before the type name to apply to all instances of the type. Additionally, when warn_misplaced_attr_for_class_type is called, it diagnoses something and so it is fine to drop the attributes then on the floor, but in case it wasn't a type decision, it silently discarded the attributes, which is invalid for the ignorability of standard attributes paper. This patch in that case adds them to decl_specs->std_attributes and let it be diagnosed later (e.g. in grokdeclarator). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-08-30 Jakub Jelinek PR c++/110345 * parser.cc (cp_parser_decl_specifier_seq): Call warn_misplaced_attr_for_class_type for all OVERLOAD_TYPE_P types, not just CLASS_TYPE_P. When not calling warn_misplaced_attr_for_class_type, don't clear attrs and add it to decl_specs->std_attributes instead. * g++.dg/cpp0x/gen-attrs-85.C: New test. Jakub --- gcc/cp/parser.cc.jj 2024-08-30 12:55:17.875362909 +0200 +++ gcc/cp/parser.cc 2024-08-30 13:44:42.485290076 +0200 @@ -16565,13 +16565,13 @@ cp_parser_decl_specifier_seq (cp_parser* diagnose_misapplied_contracts (attrs); attrs = NULL_TREE; } - else if (decl_specs->type && CLASS_TYPE_P (decl_specs->type)) + else if (decl_specs->type + && decl_specs->type_definition_p + && OVERLOAD_TYPE_P (decl_specs->type)) { - /* This is an attribute following a - class-specifier. */ - if (decl_specs->type_definition_p) - warn_misplaced_attr_for_class_type (token->location, - decl_specs->type); + /* This is an attribute following a class-specifier. */ + warn_misplaced_attr_for_class_type (token->location, + decl_specs->type); attrs = NULL_TREE; } else --- gcc/testsuite/g++.dg/cpp0x/gen-attrs-85.C.jj 2024-08-30 13:54:12.356968839 +0200 +++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-85.C 2024-08-30 13:54:05.846052485 +0200 @@ -0,0 +1,7 @@ +// { dg-do compile { target c++11 } } + +struct S {}; +struct S [[gnu::deprecated]] s; // { dg-warning "attribute ignored" } +// { dg-message "an attribute that appertains to a type-specifier is ignored" "" { target *-*-* } .-1 } +enum E {} [[gnu::deprecated]]; // { dg-warning "attribute ignored in declaration of 'enum E'" } +// { dg-message "attribute for 'enum E' must follow the 'enum' keyword" "" { target *-*-* } .-1 }