This is gcc (GCC) 14.0.1 20240411 (Red Hat 14.0.1-0) on Fedora 40 x86-64. Put this code into the file t.i: extern char const *foo () __attribute__ ((returns_nonnull)); char const * foo () { return "abc"; } and compile it with: gcc -S -O2 -Wsuggest-attribute=returns_nonnull t.i The output is: t.i: In function ‘foo’: t.i:3:3: warning: function might be candidate for attribute ‘returns_nonnull’ [-Wsuggest-attribute=returns_nonnull] 3 | foo () | ^~~ This diagnostic is obviously wrong, as foo is already declared with the suggested attribute.
Confirmed. The code which calls warn_function_returns_nonnull (or maybe warn_function_returns_nonnull should do the check) does not check for the attribute already there.
The code to do the warning was added with r14-5628-g53ba8d669550d3 .