diff options
author | David Tardon <dtardon@redhat.com> | 2017-12-27 16:17:38 +0100 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2017-12-27 16:31:57 +0100 |
commit | a5f8b6a26736874de1f8c88c0bba76d862e05b0c (patch) | |
tree | 2f4a252a99c7a897e6356ca7566a59de5968f605 | |
parent | 19b150475fcb45678cbc8ce1620efa53d9bf85d7 (diff) |
suppress GCC 7 fallthrough warnings
Change-Id: I2bf8d7c5d1b795fec06a5eb397c7be5bd6c8e580
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | m4/dlp_fallthrough.m4 | 65 | ||||
-rw-r--r-- | src/lib/MSPUBParser.cpp | 2 | ||||
-rw-r--r-- | src/lib/PolygonUtils.cpp | 2 | ||||
-rw-r--r-- | src/lib/libmspub_utils.h | 8 |
5 files changed, 76 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac index 453ea73..a7a5efb 100644 --- a/configure.ac +++ b/configure.ac @@ -34,6 +34,7 @@ LT_INIT([win32-dll disable-static pic-only]) AC_CANONICAL_HOST AX_CXX_COMPILE_STDCXX_11 +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@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/MSPUBParser.cpp b/src/lib/MSPUBParser.cpp index 179f8ae..1e94115 100644 --- a/src/lib/MSPUBParser.cpp +++ b/src/lib/MSPUBParser.cpp @@ -2448,7 +2448,7 @@ MSPUBBlockInfo MSPUBParser::parseBlock(librevenge::RVNGInputStream *input, bool case 24: //FIXME: Not doing anything with this data for now. skipBlock(input, info); - // fall-through intended + MSPUB_FALLTHROUGH; default: info.data = 0; } diff --git a/src/lib/PolygonUtils.cpp b/src/lib/PolygonUtils.cpp index 7c0ff80..109b3e4 100644 --- a/src/lib/PolygonUtils.cpp +++ b/src/lib/PolygonUtils.cpp @@ -6335,7 +6335,7 @@ void writeCustomShape(ShapeType shapeType, librevenge::RVNGPropertyList &graphic } hasUnclosedElements = false; } - //intentionally no break + MSPUB_FALLTHROUGH; case ENDSUBPATH: MSPUB_DEBUG_MSG(("ENDSUBPATH\n")); if (closeEverything && bool(pathBegin)) diff --git a/src/lib/libmspub_utils.h b/src/lib/libmspub_utils.h index b1df43b..7d6b836 100644 --- a/src/lib/libmspub_utils.h +++ b/src/lib/libmspub_utils.h @@ -25,6 +25,14 @@ #include "MSPUBTypes.h" +#if defined(HAVE_CLANG_ATTRIBUTE_FALLTHROUGH) +# define MSPUB_FALLTHROUGH [[clang::fallthrough]] +#elif defined(HAVE_GCC_ATTRIBUTE_FALLTHROUGH) +# define MSPUB_FALLTHROUGH __attribute__((fallthrough)) +#else +# define MSPUB_FALLTHROUGH ((void) 0) +#endif + // do nothing with debug messages in a release compile #ifdef DEBUG #define MSPUB_DEBUG_MSG(M) printf M |