+2019-11-20 Joseph Myers <joseph@codesourcery.com>
+
+ * c-decl.c (c_warn_type_attributes): New function.
+ (groktypename, grokdeclarator, finish_declspecs): Call
+ c_warn_type_attributes before applying attributes to types.
+ * c-tree.h (c_warn_type_attributes): Declare.
+
2019-11-19 Joseph Myers <joseph@codesourcery.com>
* c-decl.c (c_warn_unused_attributes): Use pedwarn not warning for
warning (OPT_Wattributes, "%qE attribute ignored",
get_attribute_name (t));
}
+
+/* Warn for standard attributes being applied to a type that is not
+ being defined, where that is a constraint violation, and return a
+ list of attributes with them removed. */
+
+tree
+c_warn_type_attributes (tree attrs)
+{
+ tree *attr_ptr = &attrs;
+ while (*attr_ptr)
+ if (get_attribute_namespace (*attr_ptr) == NULL_TREE)
+ {
+ pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored",
+ get_attribute_name (*attr_ptr));
+ *attr_ptr = TREE_CHAIN (*attr_ptr);
+ }
+ else
+ attr_ptr = &TREE_CHAIN (*attr_ptr);
+ return attrs;
+}
\f
/* Called when a declaration is seen that contains no names to declare.
If its type is a reference to a structure, union or enum inherited
DEPRECATED_NORMAL);
/* Apply attributes. */
+ attrs = c_warn_type_attributes (attrs);
decl_attributes (&type, attrs, 0);
return type;
if (cxx11_attribute_p (attrs) && inner_decl->kind == cdk_id)
returned_attrs = chainon (returned_attrs, attrs);
else
- returned_attrs = decl_attributes (&type,
- chainon (returned_attrs,
- attrs),
- attr_flags);
+ {
+ attrs = c_warn_type_attributes (attrs);
+ returned_attrs = decl_attributes (&type,
+ chainon (returned_attrs,
+ attrs),
+ attr_flags);
+ }
break;
}
case cdk_array:
}
if (specs->type != NULL)
{
+ specs->postfix_attrs = c_warn_type_attributes (specs->postfix_attrs);
decl_attributes (&specs->type, specs->postfix_attrs, 0);
specs->postfix_attrs = NULL_TREE;
}
extern tree c_builtin_function_ext_scope (tree);
extern tree c_simulate_builtin_function_decl (tree);
extern void c_warn_unused_attributes (tree);
+extern tree c_warn_type_attributes (tree);
extern void shadow_tag (const struct c_declspecs *);
extern void shadow_tag_warned (const struct c_declspecs *, int);
extern tree start_enum (location_t, struct c_enum_contents *, tree);
+2019-11-20 Joseph Myers <joseph@codesourcery.com>
+
+ * gcc.dg/c2x-attr-deprecated-2.c, gcc.dg/c2x-attr-fallthrough-2.c,
+ gcc.dg/c2x-attr-maybe_unused-2.c: Expect errors for invalid uses
+ of standard attributes on types. Add more tests of invalid uses
+ on types.
+
2019-11-19 Jakub Jelinek <jakub@redhat.com>
PR c++/92414
[[deprecated]]; /* { dg-error "ignored" } */
-int [[deprecated]] var; /* { dg-warning "ignored" } */
-/* { dg-message "that appertains to a type-specifier" "appertains" { target *-*-* } .-1 } */
+int [[deprecated]] var; /* { dg-error "ignored" } */
-int array_with_dep_type[2] [[deprecated]]; /* { dg-warning "ignored" } */
-/* { dg-message "that appertains to a type-specifier" "appertains" { target *-*-* } .-1 } */
+int array_with_dep_type[2] [[deprecated]]; /* { dg-error "ignored" } */
-void fn_with_dep_type () [[deprecated]]; /* { dg-warning "ignored" } */
-/* { dg-message "that appertains to a type-specifier" "appertains" { target *-*-* } .-1 } */
+void fn_with_dep_type () [[deprecated]]; /* { dg-error "ignored" } */
+
+int z = sizeof (int [[__deprecated__]]); /* { dg-error "ignored" } */
void
f (void)
[[fallthrough]]; /* { dg-error "'fallthrough' attribute at top level" } */
-int [[fallthrough]] x; /* { dg-warning "ignored" } */
-/* { dg-message "that appertains to a type-specifier" "appertains" { target *-*-* } .-1 } */
+int [[fallthrough]] x; /* { dg-error "ignored" } */
-int g () [[fallthrough]]; /* { dg-warning "ignored" } */
-/* { dg-message "that appertains to a type-specifier" "appertains" { target *-*-* } .-1 } */
+int g () [[fallthrough]]; /* { dg-error "ignored" } */
+
+int array[2] [[fallthrough]]; /* { dg-error "ignored" } */
+
+int z = sizeof (int [[fallthrough]]); /* { dg-error "ignored" } */
int
f (int a)
[[maybe_unused]]; /* { dg-error "ignored" } */
-int [[maybe_unused]] var; /* { dg-warning "ignored" } */
-/* { dg-message "that appertains to a type-specifier" "appertains" { target *-*-* } .-1 } */
+int [[maybe_unused]] var; /* { dg-error "ignored" } */
-int array_with_dep_type[2] [[maybe_unused]]; /* { dg-warning "ignored" } */
-/* { dg-message "that appertains to a type-specifier" "appertains" { target *-*-* } .-1 } */
+int array_with_dep_type[2] [[maybe_unused]]; /* { dg-error "ignored" } */
-void fn_with_dep_type () [[maybe_unused]]; /* { dg-warning "ignored" } */
-/* { dg-message "that appertains to a type-specifier" "appertains" { target *-*-* } .-1 } */
+void fn_with_dep_type () [[maybe_unused]]; /* { dg-error "ignored" } */
+
+int z = sizeof (int [[__maybe_unused__]]); /* { dg-error "ignored" } */
void
f (void)