Re: Proposal: Add more compile-time asserts to exposeinconsistencies. - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: Proposal: Add more compile-time asserts to exposeinconsistencies.
Date
Msg-id 04f13882-9625-c2b9-d6d2-8a2f3f24ac4e@2ndquadrant.com
Whole thread Raw
In response to RE: Proposal: Add more compile-time asserts to exposeinconsistencies.  ("Smith, Peter" <peters@fast.au.fujitsu.com>)
Responses Re: Proposal: Add more compile-time asserts to expose inconsistencies.  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers
On 2019-10-10 00:52, Smith, Peter wrote:
> I liked your idea of using an extern function declaration for implementing the file-scope compile-time asserts. AFAIK
itis valid standard C.
 
> 
> Thank you for the useful link to that compiler explorer. I tried many scenarios of the new StaticAssertDecl and all
seemedto 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
variablesthey are asserting. 
 
> 

The problem with this implementation is that you get a crappy error
message when the assertion fails, namely something like:

../../../../src/include/c.h:862:84: error: size of array
'static_assert_failure' is negative

Ideally, the implementation should end up calling _Static_assert()
somehow, so that we get the compiler's native error message.

We could do a configure check for whether _Static_assert() works at file
scope.  I don't know what the support for that is, but it seems to work
in gcc and clang.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services



pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: errbacktrace
Next
From: Eugen Konkov
Date:
Subject: Proposition to use '==' as synonym for 'IS NOT DISTINCT FROM'