RE: Proposal: Add more compile-time asserts to expose inconsistencies.

From: "Smith, Peter" <peters(at)fast(dot)au(dot)fujitsu(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>, Dagfinn Ilmari Mannsåker <ilmari(at)ilmari(dot)org>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: RE: Proposal: Add more compile-time asserts to expose inconsistencies.
Date: 2019-09-19 04:46:27
Message-ID: 201DD0641B056142AC8C6645EC1B5F62014B8EBDBB@SYD1217
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

-----Original Message-----
From: Michael Paquier <michael(at)paquier(dot)xyz> Sent: Thursday, 19 September 2019 11:08 AM

>On Wed, Sep 18, 2019 at 04:46:30PM +0100, Dagfinn Ilmari Mannsåker wrote:
>> Postgres doesn't seem to have it, but it would be possible to define a
>> StaticAssertDecl macro that can be used at the file level, outside any
>> function. See for example Perl's STATIC_ASSERT_DECL:
>That sounds like a cleaner alternative. Thanks for the pointer.

In the attached patch example I have defined a new macro StaticAssertDecl. A typical usage of it is shown in the relpath.c file.

The goal was to leave all existing Postgres static assert macros unchanged, but to allow static asserts to be added in the code at file scope without the need for the explicit ct_asserts function.

Notice, in reality the StaticAssertDecl macro still uses a static function as a wrapper for the StaticAssertStmt, but now the function is not visible in the source.

If this strategy is acceptable I will update my original patch to remove all those ct_asserts functions, and instead put each StaticAssertDecl nearby the array that it is asserting (e.g. just like relpath.c)

Kind Regards,
Peter Smith
Fujitsu Australia

Attachment Content-Type Size
add_more_ct_asserts_StaticAssertDecl.patch application/octet-stream 4.8 KB

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Fabien COELHO 2019-09-19 04:55:32 Re: pgbench - allow to create partitioned tables
Previous Message Michael Paquier 2019-09-19 04:43:00 Re: Allow CLUSTER, VACUUM FULL and REINDEX to change tablespace on the fly