[libc-commits] [libc] [libc] Use __attribute__((__noreturn__)) for _Noreturn in C < 11 (PR #121252)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Tue Jan 7 09:20:28 PST 2025


================
@@ -52,6 +52,16 @@
 #undef __restrict
 #define __restrict restrict // C99 and above support the restrict keyword.
 
+#undef _Noreturn
+#if __STDC_VERSION__ >= 201112L
+// In C11 and later, _Noreturn is a keyword.
----------------
nickdesaulniers wrote:

woah, so I was familiar with the keyword, but for some reason I had a hunch there was also a function attribute using the C23 `[[]]` syntax...turns out there is! lol

So there's BOTH they keyword / "function specifier" `_Noreturn`, AND the function attribute `[[noreturn]]` (sounds like `[[_Noreturn]]` is supported but "obsolescent." See footnote 175 of n3220) (and the GNU function attribute syntax). Looks like C23 also added `__has_c_attribute` preprocessor directive, but I'm guessing that's not yet widely supported by many versions of gcc+clang.

https://github.com/llvm/llvm-project/pull/121252


More information about the libc-commits mailing list