-
- Downloads
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.
Showing
- gcc/attribs.cc 13 additions, 0 deletionsgcc/attribs.cc
- gcc/attribs.h 1 addition, 0 deletionsgcc/attribs.h
- gcc/cp/decl.cc 2 additions, 1 deletiongcc/cp/decl.cc
- gcc/cp/name-lookup.cc 2 additions, 2 deletionsgcc/cp/name-lookup.cc
- gcc/cp/parser.cc 5 additions, 6 deletionsgcc/cp/parser.cc
- gcc/testsuite/g++.dg/warn/Wno-attributes-1.C 52 additions, 0 deletionsgcc/testsuite/g++.dg/warn/Wno-attributes-1.C
Loading
Please register or sign in to comment