Michael Paquier <michael@paquier.xyz> writes:
> On Wed, Sep 18, 2019 at 06:46:24AM +0000, Smith, Peter wrote:
>> I have identified some OSS code where more compile-time asserts could be added.
>>
>> Mostly these are asserting that arrays have the necessary length to
>> accommodate the enums that are used to index into them.
>>
>> In general the code is already commented with warnings such as:
>> * "If you add a new entry, remember to ..."
>> * "When modifying this enum, update the table in ..."
>> * "Display names for enums in ..."
>> * etc.
>>
>> But comments can be accidentally overlooked, so adding the
>> compile-time asserts can help eliminate human error.
>
> For some of them it could help, and we could think about a better
> location for that stuff than an unused routine.
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:
https://github.com/Perl/perl5/blob/v5.30.0/perl.h#L3455-L3488
- ilmari
--
"The surreality of the universe tends towards a maximum" -- Skud's Law
"Never formulate a law or axiom that you're not prepared to live with
the consequences of." -- Skud's Meta-Law