[2/2] batctl: suppress implicit-fallthrough compiler warning

Message ID 20170613082600.24910-3-philipp.psurek@gmail.com (mailing list archive)
State Superseded, archived
Delegated to: Simon Wunderlich
Headers
Series [1/2] batctl: change PATH_BUFF_LEN to maximal possible value |

Commit Message

Philipp Psurek June 13, 2017, 8:26 a.m. UTC
  GCC 7.1.0 complains about an intended fallthrough.
“__attribute__ ((fallthrough))” in this part of code would suppress this
warning. Because older GCC compiler don’t understand this statement attribute
and because there is already a comment in the source containing
“falls?[ \t-]*thr(ough|u)” we can suppress the warning with the
“-Wimplicit-fallthrough=2” warning option. Unintended fallthroughs without a
comment will trigger this warning.

Older GCC compiler don’t understand this warning option and exits with error.
There has to be a compiler recognition after that only GCC =>7.1.0 receives
this option.

Signed-off-by: Philipp Psurek <philipp.psurek@gmail.com>
---
 Makefile | 5 +++++
 1 file changed, 5 insertions(+)
  

Comments

Simon Wunderlich June 13, 2017, 8:48 a.m. UTC | #1
On Tuesday, June 13, 2017 10:26:00 AM CEST Philipp Psurek wrote:
> GCC 7.1.0 complains about an intended fallthrough.
> “__attribute__ ((fallthrough))” in this part of code would suppress this
> warning. Because older GCC compiler don’t understand this statement
> attribute and because there is already a comment in the source containing
> “falls?[ \t-]*thr(ough|u)” we can suppress the warning with the
> “-Wimplicit-fallthrough=2” warning option. Unintended fallthroughs without a
> comment will trigger this warning.
> 
> Older GCC compiler don’t understand this warning option and exits with
> error. There has to be a compiler recognition after that only GCC =>7.1.0
> receives this option.
> 
> Signed-off-by: Philipp Psurek <philipp.psurek@gmail.com>
> ---
>  Makefile | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/Makefile b/Makefile
> index 6bebb7d..29b7e2f 100755
> --- 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++ --std=c++17 -E -P - <<< __cplusplus),201703L)
> +       CFLAGS += -Wimplicit-fallthrough=2
> +endif
> +

Hmm, I don't like this one too much, since it looks cryptic and we will have 
to add up new versions, which I'd like to avoid.

Did you try to change the wording? I've googled a bit and it seems a comment 
containing the wording "fallthrough" will avoid it. Maybe we should just 
change "fall through" to "fallthrough"?

Thanks,
      Simon
  
Philipp Psurek June 13, 2017, 10:39 a.m. UTC | #2
Am Dienstag, den 13.06.2017, 10:48 +0200 schrieb Simon Wunderlich:
> Hmm, I don't like this one too much, since it looks cryptic and we
> will have to add up new versions, which I'd like to avoid.
> 
> Did you try to change the wording? I've googled a bit and it seems a
> comment containing the wording "fallthrough" will avoid it. Maybe we should
> just change "fall through" to "fallthrough"?

I also read about the wording but for some reason I do not want to change the
comment; because the many changes I tried were not recognized without a
compiler warning option in conjunction with the complete comment. The now
provided patch is recognized but the comment looks a little bit messed up. It
works if you don't mind the formatting of the code.

Thanks for the opportunity to contribute something to B.A.T.M.A.N.-Advanced.

Best regards,

Philipp
  
Philipp Psurek June 13, 2017, 11:08 a.m. UTC | #3
Sorry for the many posts but this one works also; the comment has to be 
definitely split up into two parts if you do not want to append warning options
to the compiler.
  

Patch

diff --git a/Makefile b/Makefile
index 6bebb7d..29b7e2f 100755
--- 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++ --std=c++17 -E -P - <<< __cplusplus),201703L)
+       CFLAGS += -Wimplicit-fallthrough=2
+endif
+
 # standard install paths
 PREFIX = /usr/local
 SBINDIR = $(PREFIX)/sbin