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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Georgios Kokolatos <gkokolatos(at)pm(dot)me>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Refactor compile-time assertion checks for C/C++
Date: 2020-03-21 23:22:41
Message-ID: 31508.1584832961@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Michael Paquier <michael(at)paquier(dot)xyz> writes:
> 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); }))

Hm, I'm not so sure. I just noticed that cpluspluscheck is failing
for me now:

$ src/tools/pginclude/cpluspluscheck
In file included from /tmp/cpluspluscheck.HRgpVA/test.cpp:4:
./src/include/common/int128.h: In function 'void int128_add_int64_mul_int64(INT128*, int64, int64)':
./src/include/common/int128.h:180: error: types may not be defined in 'sizeof' expressions

which of course is pointing at

StaticAssertStmt(((int64) -1 >> 1) == (int64) -1,
"arithmetic right shift is needed");

so the existing "C and C++" fallback StaticAssertStmt doesn't work for
older g++. (This is g++ 4.4.7 from RHEL6.)

> But then problems come from MSVC which does not like the do{} part for
> statements, and this works:

Huh? Surely do{} is a legal statement.

Maybe we should just revert b7f64c64d instead of putting more time
into this. It's looking like we're going to end up with four or so
implementations no matter what, so it's getting hard to see any
real benefit.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Phillip Black 2020-03-21 23:48:03 Database recovery from tablespace only
Previous Message Noah Misch 2020-03-21 22:49:20 Re: [HACKERS] WAL logging problem in 9.4.3?