| 1 |
.\" Copyright, the authors of the Linux man-pages project |
| 2 |
.\" |
| 3 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 4 |
.\" |
| 5 |
.TH gnu::warning 3attr 2025-11-11 "Linux man-pages 6.18" |
| 6 |
.SH NAME |
| 7 |
gnu::warning, gnu::error |
| 8 |
\- |
| 9 |
diagnose function calls not removed by optimizations |
| 10 |
.SH SYNOPSIS |
| 11 |
.nf |
| 12 |
.BI [[gnu::warning( msg )]] |
| 13 |
.BI [[gnu::error( msg )]] |
| 14 |
.fi |
| 15 |
.SH DESCRIPTION |
| 16 |
This attribute can be applied to a function. |
| 17 |
If the function call is not removed by optimizations, |
| 18 |
a diagnostic is emitted. |
| 19 |
The diagnostic contains the message |
| 20 |
.I msg |
| 21 |
and the location of the call in the source code. |
| 22 |
.P |
| 23 |
.B [[gnu::error()]] |
| 24 |
terminates the compilation |
| 25 |
after emitting the diagnostic. |
| 26 |
.SH VERSIONS |
| 27 |
.TP |
| 28 |
.BI __attribute__((warning( msg ))) |
| 29 |
.TQ |
| 30 |
.BI __attribute__((error( msg ))) |
| 31 |
.SH STANDARDS |
| 32 |
GNU. |
| 33 |
.SH HISTORY |
| 34 |
gcc 4.3, |
| 35 |
g++ 4.3, |
| 36 |
clang 14, |
| 37 |
clang++ 14. |
| 38 |
.SH CAVEATS |
| 39 |
This diagnostic is emitted by the compiler, |
| 40 |
so it doesn't take into account linker optimizations. |
| 41 |
.SH EXAMPLES |
| 42 |
.EX |
| 43 |
#include <stdlib.h> |
| 44 |
\& |
| 45 |
[[gnu::warning("foo")]] void dontcall(void); |
| 46 |
\& |
| 47 |
int |
| 48 |
main(void) |
| 49 |
{ |
| 50 |
dontcall(); // Warning. |
| 51 |
\& |
| 52 |
if (0) |
| 53 |
dontcall(); // No warning. |
| 54 |
\& |
| 55 |
exit(EXIT_SUCCESS); |
| 56 |
} |
| 57 |
.EE |