bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: undefined behaviour findings in bitset


From: Akim Demaille
Subject: Re: undefined behaviour findings in bitset
Date: Mon, 18 Mar 2019 09:16:06 +0100



Le 17 mars 2019 à 20:27, Bruno Haible <address@hidden> a écrit :

Hi Akim,

But GCC 4.7 does not support [[noreturn]] yet, even in gnu++11 mode.

I need something like the following changes.

-# if 201103 <= (defined __cplusplus ? __cplusplus : 0)
+# if (201103 <= (defined __cplusplus ? __cplusplus : 0) \
+      && 4 < __GNUC__ + (8 <= __GNUC_MINOR__))

Something like this is OK. But this change drops support for [[noreturn]]
in compilers other than GCC and clang.

😱

Shouldn't it be like this:

 # if (201103 <= (defined __cplusplus ? __cplusplus : 0) \
       && (!defined __GNUC__ || 4 < __GNUC__ + (8 <= __GNUC_MINOR__)))

Yes, of course :(  Thanks!  Fixed and pushed,

Wouldn't it be useful to have a file that defines macros such as
GL_GCC_VERSION (that is defined on GCC only, not clang, nor icc),
GL_ICC_VERSION, etc.?

The effort to distribute (in a module) and include this file may well
be larger than the gain, no?

Actually I was thinking about putting this in config.h, so that we
would even benefit from it at configure-time.

It would also help casual gnulib contributors like me be shielded
from compilers that pretend to be GCC.  For instance we should
probably tune the snippet above even further, since Clang 7
pretends to be GCC 4.2 (__GNUC__ __GNUC_MINOR__).


Also, in this case the code duplication is between a file in m4/ and
a file in lib/. However, we don't have a good way to share code between
m4/ and lib/, because an include statement in a .m4 file
#include "$srcdir/lib/foo.h"
would need to reference the gnulib-tool --source-base value instead of 'lib'.

Yep, I can see the problem.  But I would probably have tried to deal
with it the other way round: generate the *.h file from the macro.
Yet I don't know all the places where _Noreturn.h is used, so maybe
it's not (easily) doable.

Also, the relationship with noreturn.h is not completely clear for
me either.  For instance I see it already has the above fix for
GCC 4.7, but in a different way.

 /* Use ISO C++11 syntax when the compiler supports it.  */
# if (__cplusplus >= 201103 && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
    || (_MSC_VER >= 1900)
#  define _GL_NORETURN_FUNC [[noreturn]]

And I just discovered stdnoreturn.in.h which has a third approach,
configure-based.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]