https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103960
Bug ID: 103960 Summary: Clang's -Wunknown-attributes is more useful than -Wattributes Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: diagnostic Severity: enhancement Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- (This is really c-family not c) GCC's -Wattributes is used for both completely unknown attributes (e.g. the user has a typo, or they use a new attribute on an old GCC) and for misplaced attributes (e.g. a function attribute on a variable). This leaves users wondering what they've done wrong. For example, GCC 9 prints this because 'access' was added in GCC 10: f.c:5:1: warning: ‘access’ attribute directive ignored [-Wattributes] 5 | __attribute__ ((access (read_only, 1))) bool my_func (const MyStruct * const self); | ^~~~~~~~~~~~~ This doesn't tell the user *why* it was ignored. Did they just use the wrong grammar? You have to be quite familiar with GCC to know that using it in the wrong place would give a different diagnostic: f.c:5:1: warning: ‘access’ attribute only applies to function types [-Wattributes] 5 | bool my_func (const MyStruct * const __attribute__ ((access (read_only, 1))) self); | ^~~~ Apart from the caret being in the wrong place, this is pretty good. But for unknown attributes our diagnostic is vague about what the problem is. Clang's -Wunknown-attributes is more explicit: f.c:5:17: warning: unknown attribute 'access' ignored [-Wunknown-attributes] __attribute__ ((access (read_only, 1))) bool my_func (const MyStruct * const self); ^~~~~~~~~~~~~~~~~~~~~ This tells you clearly that clang simply doesn't recognize the 'access' attribute. Could we just add the word "unknown" to the diagnostic for unrecognised attributes?