Use fallthrough attributes only in C++ mode

GCC 7 defines __has_cpp_attribute even when invoked as "gcc" (possibly,
Clang does the same, according to a comment in the code, did not test
myself).

Hence, define the fallthrough declaration (as C++11 attributes)
only when compiling as C++, otherwise we pick them up even in C mode,
and they cause build failures.

Change-Id: I3f13205e014bb1dea59ee3664b29111521a7eae3
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
This commit is contained in:
Giuseppe D'Angelo 2017-04-03 20:48:33 +01:00
parent e1d3c8e203
commit c807dc3c12

View File

@ -1328,11 +1328,10 @@
Q_ASSUME_IMPL(valueOfExpression);\
} while (0)
#if defined(__cplusplus)
#if QT_HAS_CPP_ATTRIBUTE(fallthrough)
# define Q_FALLTHROUGH() [[fallthrough]]
#elif defined(__cplusplus)
/* Clang can not parse namespaced attributes in C mode, but defines __has_cpp_attribute */
# if QT_HAS_CPP_ATTRIBUTE(clang::fallthrough)
#elif QT_HAS_CPP_ATTRIBUTE(clang::fallthrough)
# define Q_FALLTHROUGH() [[clang::fallthrough]]
#elif QT_HAS_CPP_ATTRIBUTE(gnu::fallthrough)
# define Q_FALLTHROUGH() [[gnu::fallthrough]]