Re: Refactor compile-time assertion checks for C/C++

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Refactor compile-time assertion checks for C/C++
Дата
Msg-id 2636.1584369156@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Refactor compile-time assertion checks for C/C++  (Michael Paquier <michael@paquier.xyz>)
Ответы Re: Refactor compile-time assertion checks for C/C++  (Michael Paquier <michael@paquier.xyz>)
Список pgsql-hackers
Michael Paquier <michael@paquier.xyz> writes:
> On Fri, Mar 13, 2020 at 11:00:33AM -0400, Tom Lane wrote:
>> If we do need to change it, I'd be inclined to just use the do{}
>> block everywhere, not bothering with the extra #if test.

> Not sure what you mean here because we cannot use the do{} flavor
> either for the C fallback, no?  See for example the definitions of
> unconstify() in c.h.

Sorry for being unclear --- I just meant that we could use do{}
in StaticAssertStmt for both C and C++.  Although now I notice
that the code is trying to use StaticAssertStmt for StaticAssertExpr,
which you're right isn't going to do.  But I think something like
this would work and be a bit simpler than what you proposed:

 #else
 /* Fallback implementation for C and C++ */
 #define StaticAssertStmt(condition, errmessage) \
-    ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
+    do { struct static_assert_struct { int static_assert_failure : (condition) ? 1 : -1; }; } while(0)
 #define StaticAssertExpr(condition, errmessage) \
-    StaticAssertStmt(condition, errmessage)
+    ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
 #define StaticAssertDecl(condition, errmessage) \


            regards, tom lane



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

Предыдущее
От: Daniel Gustafsson
Дата:
Сообщение: Re: [PATCH] Use PKG_CHECK_MODULES to detect the libxml2 library
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: add types to index storage params on doc