diff options
author | Andreas Schneider <asn@samba.org> | 2017-07-26 16:33:10 +0200 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2018-03-01 04:37:41 +0100 |
commit | 05dae361b388e71701a7c646f2787315e9bd5dfb (patch) | |
tree | 8be6758b1fbec343b3e8eb0f6a39f873d9c804f4 | |
parent | 76535df3248b7f4e489d1555f27cedd151cd1a50 (diff) | |
download | samba-05dae361b388e71701a7c646f2787315e9bd5dfb.tar.gz |
lib:replace: Add FALL_THROUGH support
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
-rw-r--r-- | .ycm_extra_conf.py | 1 | ||||
-rw-r--r-- | lib/replace/replace.h | 9 | ||||
-rw-r--r-- | lib/replace/wscript | 36 |
3 files changed, 46 insertions, 0 deletions
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) |