[Libreoffice-commits] core.git: config_host/config_global.h.in configure.ac include/sal

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Sep 11 20:39:42 UTC 2018


 config_host/config_global.h.in |    3 +++
 configure.ac                   |   35 +++++++++++++++++++++++++++++++++++
 include/sal/types.h            |    8 +++++---
 3 files changed, 43 insertions(+), 3 deletions(-)

New commits:
commit 2d6df9bc36b81ab63bb5b7fe2648f156d3ed74ae
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Tue Sep 11 17:20:31 2018 +0200
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Tue Sep 11 22:39:16 2018 +0200

    Use [[fallthrough]] also with MSVC
    
    Change-Id: I840de9460c164b86dcbd96b4c0f382e1a1b609a2
    Reviewed-on: https://gerrit.libreoffice.org/60330
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

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


More information about the Libreoffice-commits mailing list