summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config_host/config_global.h.in3
-rw-r--r--configure.ac35
-rw-r--r--include/sal/types.h8
3 files changed, 43 insertions, 3 deletions
diff --git a/config_host/config_global.h.in b/config_host/config_global.h.in
index 7913460d6bf8..1c9e610f9167 100644
--- a/config_host/config_global.h.in
+++ b/config_host/config_global.h.in
@@ -23,6 +23,9 @@ Any change in this header will cause a rebuild of almost everything.
/* Compiler supports __attribute__((warn_unused)). */
#define HAVE_GCC_ATTRIBUTE_WARN_UNUSED 0
+/* [[fallthrough]] (C++17), __has_cpp_attribute(fallthrough) (C++2a): */
+#define HAVE_CPP_ATTRIBUTE_FALLTHROUGH 0
+
/* [[nodiscard]] (C++17), __has_cpp_attribute(nodiscard) (C++2a): */
#define HAVE_CPP_ATTRIBUTE_NODISCARD 0
diff --git a/configure.ac b/configure.ac
index d6560b1d4073..5c0d8a420c23 100644
--- a/configure.ac
+++ b/configure.ac
@@ -6404,6 +6404,41 @@ if test "$GCC" = yes; then
fi
AC_SUBST([HAVE_GCC_FNO_SIZED_DEALLOCATION])
+AC_MSG_CHECKING([[whether $CXX supports [[fallthrough]]]])
+AC_LANG_PUSH([C++])
+save_CXXFLAGS=$CXXFLAGS
+CXXFLAGS="$CXXFLAGS $CXXFLAGS_CXX11"
+dnl Unknown attributes must be ignored by compilers, but they do emit warnings about them:
+if test "$COM" = MSC; then
+ CXXFLAGS="$CXXFLAGS /we5030"
+else
+ CXXFLAGS="$CXXFLAGS -Werror"
+fi
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+ // There appears to be no feature-test macro for __has_cpp_attribute in C++2a, approximate
+ // by checking for __cplusplus:
+ #if __cplusplus > 201703L
+ #if !__has_cpp_attribute(fallthrough)
+ #error
+ #endif
+ #else
+ void f(int & x) {
+ switch (x) {
+ case 0:
+ ++x;
+ [[fallthrough]];
+ default:
+ ++x;
+ }
+ }
+ #endif
+ ]])], [
+ AC_DEFINE([HAVE_CPP_ATTRIBUTE_FALLTHROUGH],[1])
+ AC_MSG_RESULT([yes])
+ ], [AC_MSG_RESULT([no])])
+CXXFLAGS=$save_CXXFLAGS
+AC_LANG_POP([C++])
+
AC_MSG_CHECKING([[whether $CXX supports [[nodiscard]]]])
AC_LANG_PUSH([C++])
save_CXXFLAGS=$CXXFLAGS
diff --git a/include/sal/types.h b/include/sal/types.h
index 875f121db1ae..474a223a2ff2 100644
--- a/include/sal/types.h
+++ b/include/sal/types.h
@@ -422,10 +422,12 @@ namespace css = ::com::sun::star;
#endif
#if defined LIBO_INTERNAL_ONLY
-#if defined __clang__
-#define SAL_FALLTHROUGH [[clang::fallthrough]]
-#elif defined __GNUC__ && __GNUC__ >= 7
+#if HAVE_CPP_ATTRIBUTE_FALLTHROUGH
#define SAL_FALLTHROUGH [[fallthrough]]
+#elif defined __clang__
+ /* before Clang 3.9, according to
+ <https://en.cppreference.com/w/cpp/compiler_support#C.2B.2B17_features> */
+#define SAL_FALLTHROUGH [[clang::fallthrough]]
#else
#define SAL_FALLTHROUGH
#endif