gnu::warning(3attr)

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);
}

Standards

GNU.

History

gcc 4.3, g++ 4.3, clang 14, clang++ 14.

From man-pages 6.19-1 in Arch Linux 2026-11-01. Parsed by carta from the page's man source.