Kaydet (Commit) 2d6df9bc authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Use [[fallthrough]] also with MSVC

Change-Id: I840de9460c164b86dcbd96b4c0f382e1a1b609a2
Reviewed-on: https://gerrit.libreoffice.org/60330
Tested-by: Jenkins
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 50921d12
......@@ -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
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment