Re: Fixing MSVC's inability to detect elog(ERROR) does not return
От | Peter Eisentraut |
---|---|
Тема | Re: Fixing MSVC's inability to detect elog(ERROR) does not return |
Дата | |
Msg-id | a92097fa-a7e3-406b-a160-4988e690c6ca@eisentraut.org обсуждение исходный текст |
Ответ на | Re: Fixing MSVC's inability to detect elog(ERROR) does not return (David Rowley <dgrowleyml@gmail.com>) |
Список | pgsql-hackers |
On 02.09.25 04:57, David Rowley wrote: > On Thu, 24 Jul 2025 at 23:03, Peter Eisentraut <peter@eisentraut.org> wrote: >> Please review my patch at >> >> https://www.postgresql.org/message-id/ccb273c9-7544-4748-8638-30feba212e6e@eisentraut.org >> https://commitfest.postgresql.org/patch/5934/ > > Now that we're building with C11, here's a rebased patch with the new > pg_builtin_constant() macro. +#if defined(HAVE__BUILTIN_CONSTANT_P) +#define pg_builtin_constant(x) __builtin_constant_p(x) +#define HAVE_PG_BUILTIN_CONSTANT +#elif defined(_MSC_VER) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +#define pg_builtin_constant(x) \ + _Generic((1 ? ((void *) ((x) * (uintptr_t) 0)) : &(int) {1}), int *: 1, void *: 0) +#define HAVE_PG_BUILTIN_CONSTANT +#endif The variant using _Generic is not a full replacement for __builtin_constant_p(), because it only detects integer constant expressions. So for example, it wouldn't work in the use in src/include/utils/memutils.h, which checks for constant strings. So I think we need to be careful here to maintain the difference. I think what we could do is make a separate macro for detecting integer constant expressions (like ICE_P() in the reddit thread) and define that to __builtin_constant_p if available, else using _Generic. (We can't use _Generic on all platforms yet, that's a separate undertaking, but I think all platforms support either __builtin_constant_p or _Generic.) And then use that one for ereport. It would also be nice to provide a comment with some explanation and/or a link and credit for the _Generic expression. Btw., I think we should stick to the *_p() naming (for "predicate", I think) for compiler-intrinsic-affiliated functions/macros that report boolean results. The __STDC_VERSION__ comparison can be dropped, since that is the minimum now required. (But you need to keep defined(__STDC_VERSION__), since this won't work in C++.)
В списке pgsql-hackers по дате отправления: