Well, now it's a little bit tricky to suppress compiler warnings as anything below 7.1.0 dislike “__attribute__ ((fallthrough));” with a warning. One could tell the 7.1.0 with “-Wimplicit-fallthrough=2” to suppress the warning because there is a “falls?[ \t-]*thr(ough|u)” comment, but other compiles drop an unrecognised command line option error.
This one is not possible:
diff --git a/tp_meter.c b/tp_meter.c index 592a9ed..c1587cd 100644 --- a/tp_meter.c +++ b/tp_meter.c @@ -501,7 +501,9 @@ int tp_meter(char *mesh_iface, int argc, char **argv) case BATADV_TP_REASON_CANCEL: printf("CANCEL received: test aborted\n"); /* fall through and print the partial result */ + #if (__STDC_VERSION__ == 201112L) + __attribute__ ((fallthrough)); + #endif case BATADV_TP_REASON_COMPLETE: if (result.test_time > 0) { throughput = result.total_bytes * 1000;
because batctl is compiled with “-std=gnu99” which is predefined in the makefile. And I don't know if you like such code.
What actually works is this hack in the makefile:
--- a/Makefile +++ b/Makefile @@ -101,6 +101,11 @@ MKDIR ?= mkdir -p COMPILE.c = $(Q_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c LINK.o = $(Q_LD)$(CC) $(CFLAGS) $(LDFLAGS) $(TARGET_ARCH) +# Check for GCC >=7 +ifeq ($(shell $(CC) -x c -E -P - <<< __STDC_VERSION__),201112L) +CFLAGS += -Wimplicit-fallthrough=2 +endif + # standard install paths PREFIX = /usr/local SBINDIR = $(PREFIX)/sbin
I suggest to modify the makefile with this patch and make comments on intended fallthroughs like you already did.