return as->max_length == -2;
}
+/* Return true if the ATTRS chain contains at least one attribute which
+ is not ignored. */
+
+bool
+any_nonignored_attribute_p (tree attrs)
+{
+ for (tree attr = attrs; attr; attr = TREE_CHAIN (attr))
+ if (!attribute_ignored_p (attr))
+ return true;
+
+ return false;
+}
+
/* See whether LIST contains at least one instance of attribute ATTR
(possibly with different arguments). Return the first such attribute
if so, otherwise return null. */
extern tree make_attribute (const char *, const char *, tree);
extern bool attribute_ignored_p (tree);
extern bool attribute_ignored_p (const attribute_spec *const);
+extern bool any_nonignored_attribute_p (tree);
extern struct scoped_attributes *
register_scoped_attributes (const scoped_attribute_specs &, bool = false);
&& !diagnose_misapplied_contracts (declspecs->std_attributes))
{
location_t attr_loc = declspecs->locations[ds_std_attribute];
- if (warning_at (attr_loc, OPT_Wattributes, "attribute ignored"))
+ if (any_nonignored_attribute_p (declspecs->std_attributes)
+ && warning_at (attr_loc, OPT_Wattributes, "attribute ignored"))
inform (attr_loc, "an attribute that appertains to a type-specifier "
"is ignored");
}
DECL_ATTRIBUTES (ns) = tree_cons (name, args,
DECL_ATTRIBUTES (ns));
}
- else
+ else if (!attribute_ignored_p (d))
{
warning (OPT_Wattributes, "%qD attribute directive ignored",
name);
diagnosed = true;
}
}
- else
+ else if (!attribute_ignored_p (a))
warning (OPT_Wattributes, "%qD attribute directive ignored", name);
}
}
SET_EXPR_LOCATION (statement, statement_location);
/* Allow "[[fallthrough]];" or "[[assume(cond)]];", but warn otherwise. */
- if (std_attrs != NULL_TREE)
- warning_at (attrs_loc,
- OPT_Wattributes,
+ if (std_attrs != NULL_TREE && any_nonignored_attribute_p (std_attrs))
+ warning_at (attrs_loc, OPT_Wattributes,
"attributes at the beginning of statement are ignored");
}
}
/* Allow "[[fallthrough]];", but warn otherwise. */
- if (attr != NULL_TREE)
+ if (attr != NULL_TREE && any_nonignored_attribute_p (attr))
warning_at (loc, OPT_Wattributes,
"attributes at the beginning of statement are ignored");
}
}
- if (std_attrs != NULL_TREE && !attribute_ignored_p (std_attrs))
+ if (std_attrs != NULL_TREE && any_nonignored_attribute_p (std_attrs))
warning_at (make_location (attrs_loc, attrs_loc, parser->lexer),
OPT_Wattributes, "attribute ignored");
if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
symtab->finalize_toplevel_asm (string);
}
- if (std_attrs)
+ if (std_attrs && any_nonignored_attribute_p (std_attrs))
warning_at (asm_loc, OPT_Wattributes,
"attributes ignored on %<asm%> declaration");
}
--- /dev/null
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wno-attributes=bar:: -Wno-attributes=baz::qux" }
+
+[[foo::bar]]; // { dg-warning "attribute ignored" }
+[[bar::foo, foo::bar, baz::qux]]; // { dg-warning "attribute ignored" }
+[[bar::foo, bar::bar, baz::qux]]; // { dg-bogus "attribute ignored" }
+
+namespace [[foo::bar]] N { // { dg-warning "'bar' attribute directive ignored" }
+ int n;
+}
+namespace [[bar::foo, foo::bar, baz::qux]] O { // { dg-warning "'bar' attribute directive ignored" }
+ int o;
+}
+namespace [[bar::foo, bar::bar, baz::qux]] P { // { dg-bogus "attribute directive ignored" }
+ int p;
+}
+
+void
+foo ()
+{
+ int i = 0;
+ [[foo::bar]]; // { dg-warning "attributes at the beginning of statement are ignored" }
+ [[bar::foo, foo::bar, baz::qux]]; // { dg-warning "attributes at the beginning of statement are ignored" }
+ [[bar::foo, bar::bar, baz::qux]]; // { dg-bogus "attributes at the beginning of statement are ignored" }
+ [[foo::bar]] ++i; // { dg-warning "attributes at the beginning of statement are ignored" }
+ [[bar::foo, foo::bar, baz::qux]] ++i; // { dg-warning "attributes at the beginning of statement are ignored" }
+ [[bar::foo, bar::bar, baz::qux]] ++i; // { dg-bogus "attributes at the beginning of statement are ignored" }
+ [[foo::bar]] asm (""); // { dg-warning "attributes ignored on 'asm' declaration" }
+ [[bar::foo, foo::bar, baz::qux]] asm (""); // { dg-warning "attributes ignored on 'asm' declaration" }
+ [[bar::foo, bar::bar, baz::qux]] asm (""); // { dg-bogus "attributes ignored on 'asm' declaration" }
+ [[foo::bar]] using namespace N; // { dg-warning "'bar' attribute directive ignored" }
+ [[bar::foo, foo::bar, baz::qux]] using namespace O; // { dg-warning "'bar' attribute directive ignored" }
+ [[bar::foo, bar::bar, baz::qux]] using namespace P; // { dg-bogus "attribute directive ignored" }
+}
+
+class S
+{
+ [[foo::bar]] friend int bar (S &); // { dg-warning "attribute ignored" }
+ // { dsg-message "an attribute that appertains to a friend declaration that is not a definition is ignored" "" { target *-*-* } .-1 }
+ [[bar::foo, foo::bar, baz::qux]] friend int baz (S &); // { dg-warning "attribute ignored" }
+ // { dsg-message "an attribute that appertains to a friend declaration that is not a definition is ignored" "" { target *-*-* } .-1 }
+ [[bar::foo, bar::bar, baz::qux]] friend int qux (S &); // { dg-warning "attribute ignored" }
+ // { dsg-message "an attribute that appertains to a friend declaration that is not a definition is ignored" "" { target *-*-* } .-1 }
+public:
+ int s;
+};
+
+int [[foo::bar]] i; // { dg-warning "attribute ignored" }
+ // { dg-message "an attribute that appertains to a type-specifier is ignored" "" { target *-*-* } .-1 }
+int [[bar::foo, foo::bar, baz::qux]] j; // { dg-warning "attribute ignored" }
+ // { dg-message "an attribute that appertains to a type-specifier is ignored" "" { target *-*-* } .-1 }
+int [[bar::foo, bar::bar, baz::qux]] k; // { dg-bogus "attribute ignored" }