---
name: "gnu::warning"
section: "3attr"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/gnu::warning"
---

# gnu::warning(3attr)

diagnose function calls not removed by optimizations

## NAME

gnu::warning, gnu::error - diagnose function calls not removed by optimizations

## SYNOPSIS

```
[[gnu::warning(msg)]]
[[gnu::error(msg)]]
```

## DESCRIPTION

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***)))**

  ## STANDARDS

GNU.

## HISTORY

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

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