From patchwork Fri Aug 30 17:31:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1979171 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=Xkc3jAKX; 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 4WwQDv1qVYz1yfX for ; Sat, 31 Aug 2024 03:31:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1A7C3384F01B for ; Fri, 30 Aug 2024 17:31:41 +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.133.124]) by sourceware.org (Postfix) with ESMTP id 6FF6B3858435 for ; Fri, 30 Aug 2024 17:31:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6FF6B3858435 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 6FF6B3858435 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725039084; cv=none; b=G2ZgSi54wO82tVlVhOEK3rQCOJIuelw5ET6/4SLGJ/s9hoKYz5mrrZ6nOdv/NymLKDKKZIR/x18wFQAeAYBXWTSzcLJTzmHtYDurnI+eMSgRhd+nffTO6Pv2iDhLa0T1eEQOd5pHNMau3glIAP2kEHRqkXDVxvViZPFoA4/xgjw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725039084; c=relaxed/simple; bh=5qH37K7H90OHqykvObXITGaPTWqZcKXIHnUJ0QNnFwY=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=maxSRWvZBTKGxRBjFf68PYIuy8ecS5REcB1hZHwLTEZyE7uyG2J77NimqdznA11/gPKI+KneQJwYRtdfY33ZNhG6w8sFb3JRcXmHqS+JVP4ar545U8SpKaE8lrK2Nkfa4DvqN76Cua1QCC54Or9XbmxBERR9jIlcUalUYKwFKOw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725039082; 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=8YS/zsQN0o8TKrUpJxbw+HwjLr3lIC4F9EgMZfumOK0=; b=Xkc3jAKX7le3Pr36BuVAw1Knkpk5zRP9spMLUChfVgwAXWAJatvVF2J93ltOfRSLtLO5if Yu/IjKM1BA0mtwwnbGp1RJGJrr1Djt4wuQsVWEq/J9cvc8I0m1cTTkb1esDIbC+pn9Sxrb qUz33kwUNd0Z45abYLoz51wHiSPOesg= Received: from mx-prod-mc-02.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-556-Np5LNd0eOlax3XtiOEuP1A-1; Fri, 30 Aug 2024 13:31:18 -0400 X-MC-Unique: Np5LNd0eOlax3XtiOEuP1A-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CCAAD1955D56 for ; Fri, 30 Aug 2024 17:31:17 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.29]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 446E51955F44; Fri, 30 Aug 2024 17:31:17 +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 47UHVEHR1737857 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 30 Aug 2024 19:31:14 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 47UHVEXf1737856; Fri, 30 Aug 2024 19:31:14 +0200 Date: Fri, 30 Aug 2024 19:31:14 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Diagnose attributes on class/enum declarations [PR110345] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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_H4, 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! The following testcase shows another issue where we just ignored attributes without telling user we did that. If there are any declarators, the ignoring of the attribute are diagnosed in grokdeclarator etc., but if there is none (and we don't error such as on int; ), the following patch emits diagnostics. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-08-30 Jakub Jelinek PR c++/110345 * decl.cc (check_tag_decl): Diagnose std_attributes. * g++.dg/cpp0x/gen-attrs-86.C: New test. Jakub --- gcc/cp/decl.cc.jj 2024-08-30 11:47:55.341290872 +0200 +++ gcc/cp/decl.cc 2024-08-30 15:53:31.259185581 +0200 @@ -5775,6 +5775,14 @@ check_tag_decl (cp_decl_specifier_seq *d warn_misplaced_attr_for_class_type (loc, declared_type); } + if (declspecs->std_attributes + && declared_type + && any_nonignored_attribute_p (declspecs->std_attributes) + && warning_at (declspecs->locations[ds_std_attribute], OPT_Wattributes, + "attribute ignored")) + inform (declspecs->locations[ds_std_attribute], + "an attribute that appertains to a type-specifier is ignored"); + /* Diagnose invalid application of contracts, if any. */ if (find_contract (declspecs->attributes)) diagnose_misapplied_contracts (declspecs->attributes); --- gcc/testsuite/g++.dg/cpp0x/gen-attrs-86.C.jj 2024-08-30 15:54:50.010180205 +0200 +++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-86.C 2024-08-30 15:55:29.030682043 +0200 @@ -0,0 +1,8 @@ +// { dg-do compile { target c++11 } } + +struct S {}; +struct S [[gnu::deprecated]]; // { dg-warning "attribute ignored" } +// { dg-message "an attribute that appertains to a type-specifier is ignored" "" { target *-*-* } .-1 } +enum E {}; +enum E [[gnu::deprecated]]; // { dg-warning "attribute ignored" } +// { dg-message "an attribute that appertains to a type-specifier is ignored" "" { target *-*-* } .-1 }