Hi Paul,

On 2026-02-14T13:45:59-0800, Paul Eggert wrote:
> On 2026-02-14 13:02, Alejandro Colomar wrote:
> > > The only discussion I know about in WG14 is N3483
> > > <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3483.pdf>
> > There's more in the mailing lists.
> 
> Where?

The C++ proposals mailing list is public, and is
<https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals>.

The C mailing list is not public.

I don't remember in which one it was suggested to disallow return
statements within [[noreturn]], and it's difficult to grep it.

But I've prepared a draft proposal with that.  It might be even less
controversial than alx-0087.  See below.


Cheers,
Alex

---
Name
        alx-0088r1 - 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 <[email protected]>

History
        <https://www.alejandro-colomar.es/src/alx/alx/std/wg14/alx-0088.git/>

        r0 (2026-02-14):
        -  Initial draft.

        r1 (2026-02-14):
        -  wfix

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@devuan:~/tmp$ cat nr.c
                [[noreturn]]
                void f(void)
                {
                        if (0)
                                return;

                        for (;;)
                                continue;
                }
                alx@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@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 the <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 the <b>noreturn</b> attribute
        +shall not contain a return statement.

-- 
<https://www.alejandro-colomar.es>

Attachment: signature.asc
Description: PGP signature

Reply via email to