aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-12-18 11:54:57 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2024-12-18 11:54:57 +0100
commitd003a3862aeac72d0417cc41daafdf968bdb1839 (patch)
treec105f9c789dc43156caf363e78c9237f22fd1526
parent49b142f2ef5d985dd6c4509d692ee4dfedfd4658 (diff)
downloadgcc-d003a3862aeac72d0417cc41daafdf968bdb1839.zip
gcc-d003a3862aeac72d0417cc41daafdf968bdb1839.tar.gz
gcc-d003a3862aeac72d0417cc41daafdf968bdb1839.tar.bz2
c++: Diagnose attributes on class/enum declarations [PR110345]
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. 2024-12-18 Jakub Jelinek <jakub@redhat.com> PR c++/110345 * decl.cc (check_tag_decl): Diagnose std_attributes. * g++.dg/cpp0x/gen-attrs-86.C: New test.
-rw-r--r--gcc/cp/decl.cc11
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/gen-attrs-86.C8
2 files changed, 19 insertions, 0 deletions
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 5bd0e21..135747b 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -5820,6 +5820,17 @@ check_tag_decl (cp_decl_specifier_seq *declspecs,
warn_misplaced_attr_for_class_type (loc, declared_type);
}
+ if (declspecs->std_attributes
+ && declared_type
+ && any_nonignored_attribute_p (declspecs->std_attributes))
+ {
+ auto_diagnostic_group d;
+ if (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);
diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-86.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-86.C
new file mode 100644
index 0000000..bc33846
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-86.C
@@ -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 }