[Libreoffice-commits] libcdr.git: configure.ac m4/dlp_fallthrough.m4 src/lib
David Tardon
dtardon at redhat.com
Sat Jul 29 15:03:18 UTC 2017
configure.ac | 1
m4/dlp_fallthrough.m4 | 65 +++++++++++++++++++++++++++++++++++++++++++++++++
src/lib/CMXParser.cpp | 2 -
src/lib/libcdr_utils.h | 8 ++++++
4 files changed, 75 insertions(+), 1 deletion(-)
New commits:
commit 0e23de6ce871a646f9e1f33b8b5ea90e30eb9e95
Author: David Tardon <dtardon at redhat.com>
Date: Sat Jul 29 17:02:25 2017 +0200
suppress GCC 7 fallthrough warning
Change-Id: I6a1da60f75130e897191f20910aab9a3a46b5b57
diff --git a/configure.ac b/configure.ac
index 78b34f4..39770dd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -35,6 +35,7 @@ AC_CANONICAL_HOST
AX_CXX_COMPILE_STDCXX_11
AX_GCC_FUNC_ATTRIBUTE([format])
+DLP_FALLTHROUGH
PKG_PROG_PKG_CONFIG([0.20])
diff --git a/m4/dlp_fallthrough.m4 b/m4/dlp_fallthrough.m4
new file mode 100644
index 0000000..99e6be5
--- /dev/null
+++ b/m4/dlp_fallthrough.m4
@@ -0,0 +1,65 @@
+#
+# SYNOPSIS
+#
+# DLP_FALLTHROUGH
+#
+# DESCRIPTION
+#
+# This macro checks if the compiler supports a fallthrough warning
+# suppression attribute in GCC or CLANG style.
+#
+# If a fallthrough warning suppression attribute is supported define
+# HAVE_<STYLE>_ATTRIBUTE_FALLTHROUGH.
+#
+# The macro caches its result in ax_cv_have_<style>_attribute_fallthrough
+# variables.
+#
+# LICENSE
+#
+# Copyright (c) 2017 David Tardon <dtardon at redhat.com>
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
+
+#serial 1
+
+m4_defun([_DLP_FALLTHROUGH], [
+ AS_VAR_PUSHDEF([ac_var], [ax_cv_have_$2_attribute_falltrough])
+
+ AC_CACHE_CHECK([for $1], [ac_var], [
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([
+ void foo(int &i)
+ {
+ switch (i)
+ {
+ case 0:
+ i += 1;
+ $1;
+ default:
+ i += 1;
+ }
+ }
+ ], [])
+ ],
+ dnl GCC doesn't exit with an error if an unknown attribute is
+ dnl provided but only outputs a warning, so accept the attribute
+ dnl only if no warning were issued.
+ [AS_IF([test -s conftest.err],
+ [AS_VAR_SET([ac_var], [no])],
+ [AS_VAR_SET([ac_var], [yes])])],
+ [AS_VAR_SET([ac_var], [no])])
+ ])
+
+ AS_IF([test yes = AS_VAR_GET([ac_var])],
+ [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$3_ATTRIBUTE_FALLTHROUGH), 1,
+ [Define to 1 if the system has the $4-style `fallthrough' attribute])], [])
+
+ AS_VAR_POPDEF([ac_var])
+])
+
+AC_DEFUN([DLP_FALLTHROUGH], [
+ _DLP_FALLTHROUGH([[__attribute__((fallthrough))]], [gcc], [GCC], [GNU])
+ _DLP_FALLTHROUGH([[[[clang:fallthrough]]]], [clang], [CLANG], [clang])
+])
diff --git a/src/lib/CMXParser.cpp b/src/lib/CMXParser.cpp
index 5abc4f0..de0344e 100644
--- a/src/lib/CMXParser.cpp
+++ b/src/lib/CMXParser.cpp
@@ -2297,7 +2297,7 @@ libcdr::CDRColor libcdr::CMXParser::readColor(librevenge::RVNGInputStream *input
}
case 0xff: // something funny here
input->seek(4, librevenge::RVNG_SEEK_CUR);
- // Fallthrough intended
+ CDR_FALLTHROUGH;
default:
CDR_DEBUG_MSG(("Unknown color model %i\n", colorModel));
break;
diff --git a/src/lib/libcdr_utils.h b/src/lib/libcdr_utils.h
index c9c0ec6..b1d0b9f 100644
--- a/src/lib/libcdr_utils.h
+++ b/src/lib/libcdr_utils.h
@@ -36,6 +36,14 @@
# define CDR_ATTRIBUTE_PRINTF(fmt, arg)
#endif
+#if defined(HAVE_CLANG_ATTRIBUTE_FALLTHROUGH)
+# define CDR_FALLTHROUGH [[clang::fallthrough]]
+#elif defined(HAVE_GCC_ATTRIBUTE_FALLTHROUGH)
+# define CDR_FALLTHROUGH __attribute__((fallthrough))
+#else
+# define CDR_FALLTHROUGH ((void) 0)
+#endif
+
// do nothing with debug messages in a release compile
#ifdef DEBUG
namespace libcdr
More information about the Libreoffice-commits
mailing list