From: | "Smith, Peter" <peters(at)fast(dot)au(dot)fujitsu(dot)com> |
---|---|
To: | Andres Freund <andres(at)anarazel(dot)de>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Michael Paquier <michael(at)paquier(dot)xyz>, Dagfinn Ilmari Mannsåker <ilmari(at)ilmari(dot)org>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | RE: Proposal: Add more compile-time asserts to expose inconsistencies. |
Date: | 2019-10-09 22:52:41 |
Message-ID: | 201DD0641B056142AC8C6645EC1B5F62014B92C7C1@SYD1217 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
From: Andres Freund <andres(at)anarazel(dot)de> Sent: Tuesday, 1 October 2019 3:14 AM
>I wonder if defining the fallback static assert code to something like
> extern void static_assert_func(int static_assert_failed[(condition) ? 1 : -1]); isn't a solution, however. I *think* that's standard C. Seems to work at least with gcc, clang, msvc, icc.
>
>Re standard: C99's "6.7 Declarations" + 6.7.1 defines 'declaration' to include extern specifiers and in 6.7.1 5) says "The declaration of an identifier for a function that has block scope shall have >no explicit storage-class specifier other than extern.". And "6.8 Statements and blocks", via "6.8.2 Compound statement" allows declarations in statements.
>
>You can play with a good few compilers at: https://godbolt.org/z/fl0Mzu
I liked your idea of using an extern function declaration for implementing the file-scope compile-time asserts. AFAIK it is valid standard C.
Thank you for the useful link to that compiler explorer. I tried many scenarios of the new StaticAssertDecl and all seemed to work ok.
https://godbolt.org/z/fDrmXi
The patch has been updated accordingly. All assertions identified in the original post are now adjacent the global variables they are asserting.
Kind Regards
--
Peter Smith
Fujitsu Australia
Attachment | Content-Type | Size |
---|---|---|
ct_asserts_StaticAssertDecl_2.patch | application/octet-stream | 6.6 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Tomas Vondra | 2019-10-09 23:07:59 | Re: BUG #16045: vacuum_db crash and illegal memory alloc after pg_upgrade from PG11 to PG12 |
Previous Message | Lou Picciano | 2019-10-09 22:50:20 | Re: TCP Wrappers |