gnu::warning(3attr)

πŸ“¦
version 6.20 Β· 4 versions
, in arch rolling, nixpkgs unstable

πŸ’– 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 msg you 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 πŸ¦‹

  • gcc 4.3 ⭐
  • g++ 4.3 ⭐
  • clang 14 ✨
  • 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