Re: Refactor compile-time assertion checks for C/C++ - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: Refactor compile-time assertion checks for C/C++
Date
Msg-id 20200312071232.GA1739@paquier.xyz
Whole thread Raw
In response to Re: Refactor compile-time assertion checks for C/C++  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Refactor compile-time assertion checks for C/C++
List pgsql-hackers
On Thu, Mar 12, 2020 at 12:33:21AM -0400, Tom Lane wrote:
> I looked at this and tried it on an old (non HAVE__STATIC_ASSERT)
> gcc version.  Seems to work, but I have a couple cosmetic suggestions:

Thanks for the review.

> 1. The comment block above this was never updated to mention that
> we're now catering for C++ too.  Maybe something like
>
> + * On recent C++ compilers, we can use standard static_assert().
> + *

Sounds fine to me.  Looking here this is present since GCC 4.3:
https://gcc.gnu.org/projects/cxx-status.html#cxx11

For MSVC, actually I was a bit wrong, only the flavor without error
message is supported since VS 2017, and the one we use is much older:
https://docs.microsoft.com/en-us/cpp/cpp/static-assert?view=vs-2015

So, should we add a reference about both in the new comment?  I would
actually not add them, so I have used your suggestion in the attached,
but the comment block above does that for _Static_assert().  Do you
think it is better to add some references to some of those compilers
(say GCC 4.3, MSVC)?  Just stick with your suggestion?  Or stick with
your version and replace the reference to GCC 4.6 with something like
"recent compilers"?

> 2. I think you could simplify the #elif to just
>
> #elif defined(__cplusplus) && __cpp_static_assert >= 200410
>
> Per the C standard, an unrecognized identifier in an #if condition
> is replaced by zero.  So the condition will come out false as desired
> if __cpp_static_assert isn't defined; you don't need to test that
> separately.

Thanks, indeed.
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Jeff Davis
Date:
Subject: Re: Memory-Bounded Hash Aggregation
Next
From: David Rowley
Date:
Subject: Re: Berserk Autovacuum (let's save next Mandrill)