There is a clang plugin in elfs-clang-plugins (author myself, open source) that helps.
Not yet for GCC, it might be useful, for example. if you can add it to your CI control process (if you have one) or just run it manually once in a while.
The warn_unused_result plugin will issue a warning for functions that do not have the warn_unused_result attribute. The plugin only considers functions declared or defined in the current compilation unit, therefore external libraries do not add noise.
The plugin accepts the optional arg argument, -static-only, which forces it to warn only about static functions (since changing external APIs is too much work).
Example:
int foo(void);
Compiler Output:
/tmp/test.c:1:5: warning: missing attribute warn_unused_result int foo(void);
sinelaw
source share