From: Andreas Schneider Date: Wed, 26 Jul 2017 14:33:10 +0000 (+0200) Subject: lib:replace: Add FALL_THROUGH support X-Git-Tag: talloc-2.1.12~403 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=05dae361b388e71701a7c646f2787315e9bd5dfb;p=thirdparty%2Fsamba.git lib:replace: Add FALL_THROUGH support Signed-off-by: Andreas Schneider Reviewed-by: Andrew Bartlett --- diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py index c96b59e373b..97122a9169e 100644 --- a/.ycm_extra_conf.py +++ b/.ycm_extra_conf.py @@ -47,6 +47,7 @@ flags = [ '-D_XOPEN_SOURCE_EXTENDED=1', '-DAD_DC_BUILD_IS_ENABLED=1', '-DHAVE_IPV6=1', + '-DFALL_THROUGH', '-I/usr/local/include', '-I.', '-Iauth', diff --git a/lib/replace/replace.h b/lib/replace/replace.h index 128978c561e..e2a55415e04 100644 --- a/lib/replace/replace.h +++ b/lib/replace/replace.h @@ -922,6 +922,15 @@ void rep_setproctitle(const char *fmt, ...) PRINTF_ATTRIBUTE(1, 2); #define setproctitle_init rep_setproctitle_init void rep_setproctitle_init(int argc, char *argv[], char *envp[]); #endif + +#ifndef FALL_THROUGH +# ifdef HAVE_FALLTHROUGH_ATTRIBUTE +# define FALL_THROUGH __attribute__ ((fallthrough)) +# else /* HAVE_FALLTHROUGH_ATTRIBUTE */ +# define FALL_THROUGH ((void)0) +# endif /* HAVE_FALLTHROUGH_ATTRIBUTE */ +#endif /* FALL_THROUGH */ + bool nss_wrapper_enabled(void); bool nss_wrapper_hosts_enabled(void); bool socket_wrapper_enabled(void); diff --git a/lib/replace/wscript b/lib/replace/wscript index a2e2d118477..534062ec717 100644 --- a/lib/replace/wscript +++ b/lib/replace/wscript @@ -249,6 +249,42 @@ def configure(conf): headers='stdint.h sys/atomic.h', msg='Checking for atomic_add_32 compiler builtin') + conf.CHECK_CODE(''' + #define FALL_THROUGH __attribute__((fallthrough)) + + enum direction_e { + UP = 0, + DOWN, + }; + + int main(void) { + enum direction_e key = UP; + int i = 10; + int j = 0; + + switch (key) { + case UP: + i = 5; + FALL_THROUGH; + case DOWN: + j = i * 2; + break; + default: + break; + } + + if (j < i) { + return 1; + } + + return 0; + } + ''', + 'HAVE_FALLTHROUGH_ATTRIBUTE', + addmain=False, + cflags='-Werror', + msg='Checking for fallthrough attribute') + # these may be builtins, so we need the link=False strategy conf.CHECK_FUNCS('strdup memmem printf memset memcpy memmove strcpy strncpy bzero', link=False)