diff mbox series

c++: Diagnose attributes on class/enum declarations [PR110345]

Message ID ZtIB4r8b6XaDzxtC@tucnak
State New
Headers show
Series c++: Diagnose attributes on class/enum declarations [PR110345] | expand

Commit Message

Jakub Jelinek Aug. 30, 2024, 5:31 p.m. UTC
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  <jakub@redhat.com>

	PR c++/110345
	* decl.cc (check_tag_decl): Diagnose std_attributes.

	* g++.dg/cpp0x/gen-attrs-86.C: New test.


	Jakub
diff mbox series

Patch

--- 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 }