Skip to content

Commit

Permalink
Fix clang 3 (some versions) misbehaviour for __has_attribute()
Browse files Browse the repository at this point in the history
Refs: libevent#447
Clang: https://reviews.llvm.org/rL223468 ("Modify __has_attribute so
that it only looks for GNU-style attributes")
  • Loading branch information
azat committed Jan 30, 2017
1 parent d057c45 commit ffbce57
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions util-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,18 @@
extern "C" {
#endif

#if !defined(__has_attribute)
#define __has_attribute(x) 0
/* __has_attribute() wrapper */
#ifdef __has_attribute
#define EVUTIL_HAS_ATTRIBUTE __has_attribute
#endif
/** clang 3 __has_attribute misbehaves in some versions */
#if defined(__clang__) && \
__clang__ == 1 && __clang_major__ == 3 && \
(__clang_minor__ >= 2 && __clang_minor__ <= 5)
#undef EVUTIL_HAS_ATTRIBUTE
#endif
#ifndef EVUTIL_HAS_ATTRIBUTE
#define EVUTIL_HAS_ATTRIBUTE(x) 0
#endif

/* If we need magic to say "inline", get it for free internally. */
Expand Down Expand Up @@ -312,7 +322,7 @@ ev_int32_t evutil_weakrand_range_(struct evutil_weakrand_state *seed, ev_int32_t
#define EVUTIL_UNLIKELY(p) (p)
#endif

#if __has_attribute(fallthrough)
#if EVUTIL_HAS_ATTRIBUTE(fallthrough)
#define EVUTIL_FALLTHROUGH __attribute__((fallthrough))
#else
#define EVUTIL_FALLTHROUGH /* fallthrough */
Expand Down

0 comments on commit ffbce57

Please sign in to comment.