https://gcc.gnu.org/g:d003a3862aeac72d0417cc41daafdf968bdb1839
commit r15-6329-gd003a3862aeac72d0417cc41daafdf968bdb1839 Author: Jakub Jelinek <ja...@redhat.com> Date: Wed Dec 18 11:54:57 2024 +0100 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 <ja...@redhat.com> PR c++/110345 * decl.cc (check_tag_decl): Diagnose std_attributes. * g++.dg/cpp0x/gen-attrs-86.C: New test. Diff: --- gcc/cp/decl.cc | 11 +++++++++++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-86.C | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 5bd0e2195615..135747b75e2b 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 000000000000..bc3384686d64 --- /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 }