Re: pg_attribute_noreturn(), MSVC, C11
Peter Eisentraut <peter@eisentraut.org>
From: Peter Eisentraut <peter@eisentraut.org>
To: Andres Freund <andres@anarazel.de>, pgsql-hackers@postgresql.org
Cc: Thomas Munro <thomas.munro@gmail.com>
Date: 2024-12-14T17:15:13Z
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.
Commits
-
Use standard C23 and C++ attributes if available
- 76f4b92bac87 19 (unreleased) landed
-
Swap order of extern/static and pg_nodiscard
- 05cbd6cb22d2 18.0 landed
-
pg_noreturn to replace pg_attribute_noreturn()
- 3691edfab971 18.0 landed