Commit 51940f97 authored by Tom Lane's avatar Tom Lane

Cast to void in StaticAssertExpr, not its callers.

Seems a bit silly that many (in fact all, as of today) uses of
StaticAssertExpr would need to cast it to void to avoid warnings from
pickier compilers.  Let's just do the cast right in the macro, instead.

In passing, change StaticAssertExpr to StaticAssertStmt in one
place where that seems more apropos.

Discussion: https://postgr.es/m/16161.1518715186@sss.pgh.pa.us
parent 03c5a00e
...@@ -380,10 +380,10 @@ LWLockShmemSize(void) ...@@ -380,10 +380,10 @@ LWLockShmemSize(void)
void void
CreateLWLocks(void) CreateLWLocks(void)
{ {
StaticAssertExpr(LW_VAL_EXCLUSIVE > (uint32) MAX_BACKENDS, StaticAssertStmt(LW_VAL_EXCLUSIVE > (uint32) MAX_BACKENDS,
"MAX_BACKENDS too big for lwlock.c"); "MAX_BACKENDS too big for lwlock.c");
StaticAssertExpr(sizeof(LWLock) <= LWLOCK_MINIMAL_SIZE && StaticAssertStmt(sizeof(LWLock) <= LWLOCK_MINIMAL_SIZE &&
sizeof(LWLock) <= LWLOCK_PADDED_SIZE, sizeof(LWLock) <= LWLOCK_PADDED_SIZE,
"Miscalculated LWLock padding"); "Miscalculated LWLock padding");
......
...@@ -779,7 +779,7 @@ extern void ExceptionalCondition(const char *conditionName, ...@@ -779,7 +779,7 @@ extern void ExceptionalCondition(const char *conditionName,
#define StaticAssertStmt(condition, errmessage) \ #define StaticAssertStmt(condition, errmessage) \
do { _Static_assert(condition, errmessage); } while(0) do { _Static_assert(condition, errmessage); } while(0)
#define StaticAssertExpr(condition, errmessage) \ #define StaticAssertExpr(condition, errmessage) \
({ StaticAssertStmt(condition, errmessage); true; }) ((void) ({ StaticAssertStmt(condition, errmessage); true; }))
#else /* !HAVE__STATIC_ASSERT */ #else /* !HAVE__STATIC_ASSERT */
#define StaticAssertStmt(condition, errmessage) \ #define StaticAssertStmt(condition, errmessage) \
((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; })) ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
...@@ -796,7 +796,7 @@ extern void ExceptionalCondition(const char *conditionName, ...@@ -796,7 +796,7 @@ extern void ExceptionalCondition(const char *conditionName,
#define StaticAssertStmt(condition, errmessage) \ #define StaticAssertStmt(condition, errmessage) \
do { struct static_assert_struct { int static_assert_failure : (condition) ? 1 : -1; }; } while(0) do { struct static_assert_struct { int static_assert_failure : (condition) ? 1 : -1; }; } while(0)
#define StaticAssertExpr(condition, errmessage) \ #define StaticAssertExpr(condition, errmessage) \
({ StaticAssertStmt(condition, errmessage); }) ((void) ({ StaticAssertStmt(condition, errmessage); }))
#endif #endif
#endif /* C++ */ #endif /* C++ */
...@@ -817,14 +817,14 @@ extern void ExceptionalCondition(const char *conditionName, ...@@ -817,14 +817,14 @@ extern void ExceptionalCondition(const char *conditionName,
StaticAssertStmt(__builtin_types_compatible_p(__typeof__(varname), typename), \ StaticAssertStmt(__builtin_types_compatible_p(__typeof__(varname), typename), \
CppAsString(varname) " does not have type " CppAsString(typename)) CppAsString(varname) " does not have type " CppAsString(typename))
#define AssertVariableIsOfTypeMacro(varname, typename) \ #define AssertVariableIsOfTypeMacro(varname, typename) \
((void) StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \ (StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
CppAsString(varname) " does not have type " CppAsString(typename))) CppAsString(varname) " does not have type " CppAsString(typename)))
#else /* !HAVE__BUILTIN_TYPES_COMPATIBLE_P */ #else /* !HAVE__BUILTIN_TYPES_COMPATIBLE_P */
#define AssertVariableIsOfType(varname, typename) \ #define AssertVariableIsOfType(varname, typename) \
StaticAssertStmt(sizeof(varname) == sizeof(typename), \ StaticAssertStmt(sizeof(varname) == sizeof(typename), \
CppAsString(varname) " does not have type " CppAsString(typename)) CppAsString(varname) " does not have type " CppAsString(typename))
#define AssertVariableIsOfTypeMacro(varname, typename) \ #define AssertVariableIsOfTypeMacro(varname, typename) \
((void) StaticAssertExpr(sizeof(varname) == sizeof(typename), \ (StaticAssertExpr(sizeof(varname) == sizeof(typename), \
CppAsString(varname) " does not have type " CppAsString(typename))) CppAsString(varname) " does not have type " CppAsString(typename)))
#endif /* HAVE__BUILTIN_TYPES_COMPATIBLE_P */ #endif /* HAVE__BUILTIN_TYPES_COMPATIBLE_P */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment