gnu::warning(3attr)
π gnu::warning, gnu::error β girlies, your compiler is about to call you out π
okay so real quick, this is from the 3attr section of the Linux manual, and no cap, it's one of the most "the compiler is your bestie who will absolutely read you" pages out there. let's get into it β¨
πΈ NAME πΈ
gnu::warning, gnu::error β the diagnostics that go off when a function call wasn't yeeted by optimizations π
π SYNOPSIS π
[[gnu::warning(msg)]]
[[gnu::error(msg)]]
β¨ DESCRIPTION β¨
So. You can slap this attribute onto a function. That's the whole vibe. And if the function call doesn't get removed by optimizations, the compiler straight-up emits a diagnostic at you. π«Ά
That diagnostic is carrying two things, every single time:
- the message
msgyou gave it π - the location of the call, right there in the source code π
And here's the plot twist, the main character moment: [[gnu::error()]] doesn't just yell at you β it terminates the compilation after it emits that diagnostic. like, that's it, we're done here, pack it up ππ
π VERSIONS π
the classic __attribute__ spelling also exists, both flavors:
__attribute__((warning(msg)))
__attribute__((error(msg)))
π STANDARDS π
GNU. that's it, that's the whole standard, periodt π
π¦ HISTORY π¦
gcc4.3 βg++4.3 βclang14 β¨clang++14 β¨
π CAVEATS π
Listen bestie, this is important: this diagnostic comes from the compiler, so it does not take linker optimizations into account. compiler β linker, they're not the same girl, they don't share notes. π₯
πΈ EXAMPLES πΈ
look at her. iconique. the way the if (0) one doesn't warnβ¦ chef's kiss π
#include <stdlib.h>
[[gnu::warning("foo")]] void dontcall(void);
int
main(void)
{
dontcall(); // Warning.
if (0)
dontcall(); // No warning.
exit(EXIT_SUCCESS);
}
see how the first dontcall(); gets the warning, but the one tucked inside if (0) gets nothing? because optimizations already caught that one and removed it. she's gone. no vibes to diagnose. π
aaaand that's the whole page fr fr π«Ά huge shoutout to Linux man-pages 6.20, dated 2025-11-11 β go say hi, tell her she ate πβ¨π
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms