Skip to content

Commit

Permalink
Fix FDK_FALLTHROUGH for apple clang
Browse files Browse the repository at this point in the history
In the apple branded version of clang, the [[clang::fallthrough]]
attribute isn't supported.

Directly exposing __has_cpp_attribute(clang::fallthrough) to the
preprocessor breaks when building in C mode with GCC, which forces
wrapping it in an extra layer of #ifdef __cplusplus.
  • Loading branch information
mstorsjo committed Oct 8, 2019
1 parent e154597 commit 4fe5edb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions libSYS/include/machine_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,22 @@ it. Hence, a fully platform-independant way to use alignment is not supported.
/**************************************************
* Macros regarding static code analysis
**************************************************/
#if defined(__clang__)
#ifdef __cplusplus
#if !defined(__has_cpp_attribute)
#define __has_cpp_attribute(x) 0
#endif
#if defined(__clang__) && __has_cpp_attribute(clang::fallthrough)
#define FDK_FALLTHROUGH [[clang::fallthrough]]
#elif defined(__GNUC__) && (__GNUC__ >= 7)
#endif
#endif

#ifndef FDK_FALLTHROUGH
#if defined(__GNUC__) && (__GNUC__ >= 7)
#define FDK_FALLTHROUGH __attribute__((fallthrough))
#else
#define FDK_FALLTHROUGH
#endif
#endif

#ifdef _MSC_VER
/*
Expand Down

0 comments on commit 4fe5edb

Please sign in to comment.