Use [[fallthrough]] also with MSVC

Change-Id: I840de9460c164b86dcbd96b4c0f382e1a1b609a2
Reviewed-on: https://gerrit.libreoffice.org/60330
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann 2018-09-11 17:20:31 +02:00
parent 50921d1223
commit 2d6df9bc36
3 changed files with 43 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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