gnu::warning3attr
Diagnose function calls not removed by optimizations
Usage
[[gnu::warning(msg)]] [[gnu::error(msg)]]
Overview
This attribute can be applied to a function. If the function call is not removed by optimizations, a diagnostic is emitted. The diagnostic contains the message msg and the location of the call in the source code.
[[gnu::error()]] terminates the compilation after emitting the diagnostic.
Versions
__attribute__((warning(msg)))
__attribute__((error(msg)))
Caveats
This diagnostic is emitted by the compiler, so it doesn't take into account linker optimizations.
Examples
#include <stdlib.h>
[[gnu::warning("foo")]] void dontcall(void);
int
main(void)
{
dontcall(); // Warning.
if (0)
dontcall(); // No warning.
exit(EXIT_SUCCESS);
}