Re: Refactor compile-time assertion checks for C/C++

Поиск
Список
Период
Сортировка
От Michael Paquier
Тема Re: Refactor compile-time assertion checks for C/C++
Дата
Msg-id 20200312071232.GA1739@paquier.xyz
обсуждение исходный текст
Ответ на Re: Refactor compile-time assertion checks for C/C++  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Refactor compile-time assertion checks for C/C++  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Jeff Davis
Дата:
Сообщение: Re: Memory-Bounded Hash Aggregation
Следующее
От: David Rowley
Дата:
Сообщение: Re: Berserk Autovacuum (let's save next Mandrill)