Skip to content
Snippets Groups Projects
Commit 388ab039 authored by Jakub Jelinek's avatar Jakub Jelinek
Browse files

c++: Don't diagnose ignoring of attributes if all ignored attributes are attribute_ignored_p

There is another thing I wonder about: with -Wno-attributes= we are
supposed to ignore the attributes altogether, but we are actually still
warning about them when we emit these generic warnings about ignoring
all attributes which appertain to this and that (perhaps with some
exceptions we first remove from the attribute chain), like:
void foo () { [[foo::bar]]; }
with -Wattributes -Wno-attributes=foo::bar
Shouldn't we call some helper function in cases like this and warn
not when std_attrs (or how the attribute chain var is called) is non-NULL,
but if it is non-NULL and contains at least one non-attribute_ignored_p
attribute?

I've kept warnings for cases where the C++ standard says explicitly any
attributes aren't ok -
"If an attribute-specifier-seq appertains to a friend declaration, that
declaration shall be a definition."
or
https://eel.is/c++draft/dcl.type.elab#3
or
https://eel.is/c++draft/temp.spec#temp.explicit-3

For some changes I haven't figured out how could I cover it in the
testsuite.

Note, C uses a different strategy, it has c_warn_unused_attributes
function which warns about all the attributes one by one unless they
are ignored (or allowed in certain position).
Though that is just a single diagnostic wording, while C++ FE just warns
that there are some ignored attributes and doesn't name them individually
(except for namespace and using namespace) and uses different wordings in
different spots.

2023-12-09  Jakub Jelinek  <jakub@redhat.com>

gcc/
	* attribs.h (any_nonignored_attribute_p): Declare.
	* attribs.cc (any_nonignored_attribute_p): New function.
gcc/cp/
	* parser.cc (cp_parser_statement, cp_parser_expression_statement,
	cp_parser_declaration, cp_parser_asm_definition): Don't diagnose
	ignored attributes if !any_nonignored_attribute_p.
	* decl.cc (grokdeclarator): Likewise.
	* name-lookup.cc (handle_namespace_attrs, finish_using_directive):
	Don't diagnose ignoring of attr_ignored_p attributes.
gcc/testsuite/
	* g++.dg/warn/Wno-attributes-1.C: New test.
parent 9363d919
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment