On Mon, Mar 16, 2020 at 10:35:05PM -0400, Tom Lane wrote: > Michael Paquier <mich...@paquier.xyz> writes: >> C++ does not allow defining a struct inside a sizeof() call, so in >> this case StaticAssertExpr() does not work with the previous extension >> in C++. StaticAssertStmt() does the work though. > > [ scratches head... ] A do{} is okay in an expression in C++ ??
cpp-fallback-fix.patch in [1] was doing that. The fun does not stop here. gcc is fine when using that for C and C++: #define StaticAssertStmt(condition, errmessage) \ do { struct static_assert_struct { int static_assert_failure : (condition) ? 1 : -1; }; } while(0) #define StaticAssertExpr(condition, errmessage) \ ((void) ({ StaticAssertStmt(condition, errmessage); })) But then problems come from MSVC which does not like the do{} part for statements, and this works: #define StaticAssertStmt(condition, errmessage) \ ((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; })) #define StaticAssertExpr(condition, errmessage) \ StaticAssertStmt(condition, errmessage) [1]: https://postgr.es/m/20200313115033.ga183...@paquier.xyz -- Michael
signature.asc
Description: PGP signature