mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-02 07:23:41 +02:00
gmacros: Don't define bogus __has_* macros
This pollutes the reserved compiler namespace and breaks applications trying to do their own feature detection. For instance, this falsely detects that alloca is not a builtin on gcc: #include <glib.h> #if defined(__has_builtin) # if !__has_builtin(alloca) # error "wtf glib?" # endif #else /* version-checking to determine alloca existence */ #endif Instead, define our own g_macro__has_* versions that have the behaviour that we need. https://bugzilla.gnome.org/show_bug.cgi?id=794635
This commit is contained in:
@@ -250,21 +250,23 @@ template <int w>
|
||||
|
||||
#define verify(R) _GL_VERIFY (R, "verify (" #R ")")
|
||||
|
||||
#ifndef __has_builtin
|
||||
# define __has_builtin(x) 0
|
||||
#ifdef __has_builtin
|
||||
# define _GL_MACRO__has_builtin __has_builtin
|
||||
#else
|
||||
# define _GL_MACRO__has_builtin(x) 0
|
||||
#endif
|
||||
|
||||
/* Assume that R always holds. This lets the compiler optimize
|
||||
accordingly. R should not have side-effects; it may or may not be
|
||||
evaluated. Behavior is undefined if R is false. */
|
||||
|
||||
#if (__has_builtin (__builtin_unreachable) \
|
||||
#if (_GL_MACRO__has_builtin (__builtin_unreachable) \
|
||||
|| 4 < __GNUC__ + (5 <= __GNUC_MINOR__))
|
||||
# define assume(R) ((R) ? (void) 0 : __builtin_unreachable ())
|
||||
#elif 1200 <= _MSC_VER
|
||||
# define assume(R) __assume (R)
|
||||
#elif (defined lint \
|
||||
&& (__has_builtin (__builtin_trap) \
|
||||
&& (_GL_MACRO__has_builtin (__builtin_trap) \
|
||||
|| 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__))))
|
||||
/* Doing it this way helps various packages when configured with
|
||||
--enable-gcc-warnings, which compiles with -Dlint. It's nicer
|
||||
|
Reference in New Issue
Block a user