Date: Sun, 15 Feb 2026 19:00:38 -0500
On Sat, Feb 14, 2026 at 4:51 PM Alejandro Colomar via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Hi!
>
> Here's another proposal for constraining attributes. This is likely to
> be even less controversial than that of constraining [[reproducible]]
> and [[unsequenced]]. It's worded for C2y, but the concept applies to
> C++ too.
>
>
> Have a lovely night!
> Alex
>
> ---
> Name
> alx-0088r0 - noreturn can't return
>
> Principles
> - Codify existing practice to address evident deficiencies
> - Enable secure programming
>
> And from the old C23 charter:
>
> - Trust the programmer, as a goal, is outdated in respect to
> the security and safety programming communities.
>
> Category
> Earthly demon.
>
> Author
> Alejandro Colomar <alx_at_[hidden]>
>
> History
> <https://www.alejandro-colomar.es/src/alx/alx/std/wg14/alx-0088.git/>
>
> r0 (2026-02-14):
> - Initial draft.
>
> Description
> It makes absolutely no sense to have a [[noreturn]] function
> that contains a return statement.
>
> [[noreturn]]
> void f(void)
> {
> return;
> // would you mind serving me a dose of Nasal Demons?
> }
>
> More work would be needed to make sure that [[noreturn]]
> functions can't return. This is a good start, though. A low-
> hanging fruit.
>
> Prior art
> Both GCC and Clang diagnose --by default--, even in the case
> where the return statement is unreachable.
>
> alx_at_devuan:~/tmp$ cat nr.c
> [[noreturn]]
> void f(void)
> {
> if (0)
> return;
>
> for (;;)
> continue;
> }
> alx_at_devuan:~/tmp$ gcc -S -O3 nr.c
> nr.c: In function ‘f’:
> nr.c:5:17: warning: function declared ‘noreturn’ has a ‘return’ statement
> 5 | return;
> | ^~~~~~
> alx_at_devuan:~/tmp$ clang -S -O3 nr.c
> nr.c:5:3: warning: function 'f' declared 'noreturn' should
> not return [-Winvalid-noreturn]
> 5 | return;
> | ^
> 1 warning generated.
>
> Proposed wording
> Based on N3783.
>
> 6.7.5 Function specifiers
> @@ Constraints, p5+1
> +A function declared with a <b>_Noreturn</b> function specifier
> +shall not contain a return statement.
>
> 6.7.12.7 The noreturn and _Noreturn attributes
> @@ Constraints, p2+1
> +A function declared with a <b>noreturn</b> attribute
> +shall not contain a return statement.
I think it might be worth allowing the following:
[[noreturn]]int foo();
[[noreturn]]int bar(){
return foo();//provably OK, because foo does not return
}
This is a pattern that is used, for example:
https://www.lua.org/manual/5.5/manual.html#luaL_error though noreturn
is not actually used here since C89 compatibility is intended.
>
> --
> <https://www.alejandro-colomar.es>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
<std-proposals_at_[hidden]> wrote:
>
> Hi!
>
> Here's another proposal for constraining attributes. This is likely to
> be even less controversial than that of constraining [[reproducible]]
> and [[unsequenced]]. It's worded for C2y, but the concept applies to
> C++ too.
>
>
> Have a lovely night!
> Alex
>
> ---
> Name
> alx-0088r0 - noreturn can't return
>
> Principles
> - Codify existing practice to address evident deficiencies
> - Enable secure programming
>
> And from the old C23 charter:
>
> - Trust the programmer, as a goal, is outdated in respect to
> the security and safety programming communities.
>
> Category
> Earthly demon.
>
> Author
> Alejandro Colomar <alx_at_[hidden]>
>
> History
> <https://www.alejandro-colomar.es/src/alx/alx/std/wg14/alx-0088.git/>
>
> r0 (2026-02-14):
> - Initial draft.
>
> Description
> It makes absolutely no sense to have a [[noreturn]] function
> that contains a return statement.
>
> [[noreturn]]
> void f(void)
> {
> return;
> // would you mind serving me a dose of Nasal Demons?
> }
>
> More work would be needed to make sure that [[noreturn]]
> functions can't return. This is a good start, though. A low-
> hanging fruit.
>
> Prior art
> Both GCC and Clang diagnose --by default--, even in the case
> where the return statement is unreachable.
>
> alx_at_devuan:~/tmp$ cat nr.c
> [[noreturn]]
> void f(void)
> {
> if (0)
> return;
>
> for (;;)
> continue;
> }
> alx_at_devuan:~/tmp$ gcc -S -O3 nr.c
> nr.c: In function ‘f’:
> nr.c:5:17: warning: function declared ‘noreturn’ has a ‘return’ statement
> 5 | return;
> | ^~~~~~
> alx_at_devuan:~/tmp$ clang -S -O3 nr.c
> nr.c:5:3: warning: function 'f' declared 'noreturn' should
> not return [-Winvalid-noreturn]
> 5 | return;
> | ^
> 1 warning generated.
>
> Proposed wording
> Based on N3783.
>
> 6.7.5 Function specifiers
> @@ Constraints, p5+1
> +A function declared with a <b>_Noreturn</b> function specifier
> +shall not contain a return statement.
>
> 6.7.12.7 The noreturn and _Noreturn attributes
> @@ Constraints, p2+1
> +A function declared with a <b>noreturn</b> attribute
> +shall not contain a return statement.
I think it might be worth allowing the following:
[[noreturn]]int foo();
[[noreturn]]int bar(){
return foo();//provably OK, because foo does not return
}
This is a pattern that is used, for example:
https://www.lua.org/manual/5.5/manual.html#luaL_error though noreturn
is not actually used here since C89 compatibility is intended.
>
> --
> <https://www.alejandro-colomar.es>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2026-02-16 00:03:59
