Re: Type assertions without GCC builtins

Поиск
Список
Период
Сортировка
От Jelte Fennema-Nio
Тема Re: Type assertions without GCC builtins
Дата
Msg-id DH5TWWJ8M6TL.2IHPAEFCMOG23@jeltef.nl
обсуждение исходный текст
Ответ на Re: Type assertions without GCC builtins  (Peter Eisentraut <peter@eisentraut.org>)
Список pgsql-hackers
On Wed, 19 Nov 2025 at 19:44, Peter Eisentraut <peter@eisentraut.org> wrote:
> > Presumably _Generic type resolution and StaticAssertExpr()'s
> > definition are just too much for it.  I wonder if some other phrasing
> > could help.  Posting where I got to with this, in case anyone has any
> > ideas...
>
> Yeah, I had been playing with a similar patch, which now also crashes on
> CI, but I'm pretty sure this worked at some point.  So maybe an upgrade
> or downgrade would fix it.

Attached is an updated version of Thomas his approach that passes CI. It
continues to use the sizeof fallback in StaticAssertVariableIsOfType for
VS2019. It still defines the pg_expr_has_type_p macro even for VS2019
though, because it's only the combination with StaticAssertExpr that
triggers compiler bugs not the _Generic usage itself.

> I did not consider C++.  I'm unsure what to do about it.  For the C type
> system, "compatible" is term of art, and swapping
> __builtin_types_compatible_p for _Generic is semantically equivalent.  I
> don't have the C++ experience to know what exactly std::is_same is, but
> I don't know that we want to expose ourselves to requiring types to be
> *both* C-"compatible" and C++-"same" without more guidance.

It turns out the C++ version that Thomas wrote was indeed not
equivalent. _Generic decays arrays and functions into pointers. This
starts doing the same for the C++ version. After a focussed reading of
the reference for both _Generic[1], std::decay[2] and std::is_same[3],
I'm pretty sure that these two macro definition now behave the same in
all cases. I've also included some static asserts (in the decl position
which also works on VS2019) to ensure that the behaviour is the same in
C an C++ for all cases that I expect us to use.

> I don't know what the aim of the C++ support might be.

I use this macro in my "safer and easier hash table macros" patchset[4],
not for asserts but to pick the hashing function. And I'd like for those
new macros to be useable in C++ too.

[1]: https://en.cppreference.com/w/c/language/generic.html
[2]: https://en.cppreference.com/w/cpp/types/decay.html
[3]: https://en.cppreference.com/w/cpp/types/is_same.html
[4]: https://www.postgresql.org/message-id/flat/aS2b3LoUypW1/Gdz@ip-10-97-1-34.eu-west-3.compute.internal

Вложения

В списке pgsql-hackers по дате отправления: