Re: pg_attribute_noreturn(), MSVC, C11

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Andres Freund <andres(at)anarazel(dot)de>, pgsql-hackers(at)postgresql(dot)org
Cc: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Subject: Re: pg_attribute_noreturn(), MSVC, C11
Date: 2024-12-14 17:15:13
Message-ID: 207cba7e-35fe-4309-a128-b53f7e21cc29@eisentraut.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 13.12.24 20:10, Andres Freund wrote:
> C11 has been out a while, so I'm somewhat inclined to adopt _Noreturn/noreturn
> in a conditional way. Older compilers would still work, just not understand
> noreturn.
>
> One wrinkle: _Noreturn/noreturn have been deprecated in C23, because that
> adopted C++11's attribute syntax (i.e. [[noreturn]]). But that's at least in
> the same place as _Noreturn/return.
>
> We can't remove [[noreturn]] with preprocessor magic, so it's not really
> viable to use that for, uhm, quite a while.
>
> If we were to use _Noreturn, I think it could just be something like:
>
> I think it should suffice to do something like
>
> #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
> #define pg_noreturn _Noreturn
> #else
> #define pg_noreturn
> #endif

This looks reasonable to me. We also have pg_nodiscard. (That's got a
slightly different history in the C standard, but I mean it's also
"pg_someattribute".)

> (or alternatively include stdreturn if __STDC_VERSION__ indicates support and
> define a bare 'noreturn' if not)
>
> For msvc that mean we'd need to add /std:c11 (or /std:c17) to the compiler
> flags, as it otherwise it results in a weird mix of c89 an c99). But that
> might be a good idea anyway. With one minor change [1] the tests pass with
> msvc when using /std:c17.

According to my notes, C11 requires MSVC 2019, and we currently require
2015, so this will require a bit of logic.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2024-12-14 17:18:35 Re: pg_attribute_noreturn(), MSVC, C11
Previous Message Pavel Stehule 2024-12-14 15:40:42 Re: proposal: schema variables