From e73410317b8c445f780fd6ff35a9991e0e07d51e Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Thu, 4 Jan 2018 11:20:38 +0000 Subject: [PATCH] PHPC-1084: Upgrade switch/case fallthrough comments to use GCC 7's new attribute --- config.m4 | 1 + phongo_compat.h | 15 +++++++++++++++ src/bson-encode.c | 3 ++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/config.m4 b/config.m4 index 90b5c1886..9a2217cf6 100644 --- a/config.m4 +++ b/config.m4 @@ -132,6 +132,7 @@ if test "$MONGODB" != "no"; then PHP_CHECK_GCC_ARG(-Wparentheses, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wparentheses") PHP_CHECK_GCC_ARG(-Wdeclaration-after-statement, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wdeclaration-after-statement") PHP_CHECK_GCC_ARG(-Wmaybe-uninitialized, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wmaybe-uninitialized") + PHP_CHECK_GCC_ARG(-Wimplicit-fallthrough, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wimplicit-fallthrough") PHP_CHECK_GCC_ARG(-Werror, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Werror") PHP_CHECK_GCC_ARG(-Wextra, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wextra") PHP_CHECK_GCC_ARG(-Wno-unused-parameter, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-unused-parameter") diff --git a/phongo_compat.h b/phongo_compat.h index 4e23384a8..edd7bf234 100644 --- a/phongo_compat.h +++ b/phongo_compat.h @@ -49,6 +49,21 @@ # define ARG_UNUSED #endif +#if defined (__GNUC__) +# define PHONGO_GNUC_CHECK_VERSION(major, minor) \ + ((__GNUC__ > (major)) || \ + ((__GNUC__ == (major)) && (__GNUC_MINOR__ >= (minor)))) +#else +# define PHONGO_GNUC_CHECK_VERSION(major, minor) 0 +#endif + +#if PHONGO_GNUC_CHECK_VERSION(7, 0) +# define PHONGO_BREAK_INTENTIONALLY_MISSING __attribute__ ((fallthrough)); +#else +# define PHONGO_BREAK_INTENTIONALLY_MISSING +#endif + + #if PHP_VERSION_ID >= 70000 # define phongo_char zend_string # define phongo_long zend_long diff --git a/src/bson-encode.c b/src/bson-encode.c index 8a2f518c4..4643d5a2d 100644 --- a/src/bson-encode.c +++ b/src/bson-encode.c @@ -365,7 +365,8 @@ static void php_phongo_bson_append(bson_t *bson, php_phongo_bson_flags_t flags, } break; } - /* break intentionally omitted */ + PHONGO_BREAK_INTENTIONALLY_MISSING + case IS_OBJECT: { HashTable *tmp_ht = HASH_OF(entry);