From: Andres Freund <and...@anarazel.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: ct_asserts_StaticAssertDecl_2.patch
Description: ct_asserts_StaticAssertDecl_2.patch

Reply via email to