Re: -Wimplicit-fallthrough broken?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 19/07/2017 22:18, Georg-Johann Lay wrote:

> Hi, with the following small small test I am getting these warnings:
> 
> void test1 (unsigned char c)
> {
>      switch (c)
>      {
>          case 1: c++; // fallthrough
>          case 2: c--; // FALLTHRU
>          case 3: c++; // FALLTHROUGH
>          case 4: z = c; break;
>      }
> }
> 
> void test2 (unsigned char c)
> {
>      switch (c)
>      {
>          case 1: c++;
>          /* fallthrough */
>          case 2: c--;
>          /* FALLTHRU */
>          case 3: c++;
>          /* FALLTHROUGH */
>          case 4: z = c; break;
>      }
> }
> 
> 
> 
> simple.c: In function 'test1':
> simple.c:7:18: warning: this statement may fall through 
> [-Wimplicit-fallthrough=]
>           case 1: c++; // fallthrough
>                   ~^~
> simple.c:8:9: note: here
>           case 2: c--; // FALLTHRU
>           ^~~~
> simple.c:8:18: warning: this statement may fall through 
> [-Wimplicit-fallthrough=]
>           case 2: c--; // FALLTHRU
>                   ~^~
> simple.c:9:9: note: here
>           case 3: c++; // FALLTHROUGH
>           ^~~~
> simple.c:9:18: warning: this statement may fall through 
> [-Wimplicit-fallthrough=]
>           case 3: c++; // FALLTHROUGH
>                   ~^~
> simple.c:10:9: note: here
>           case 4: z = c; break;
>           ^~~~
> simple.c: In function 'test2':
> simple.c:18:18: warning: this statement may fall through 
> [-Wimplicit-fallthrough=]
>           case 1: c++;
>                   ~^~
> simple.c:20:9: note: here
>           case 2: c--;
>           ^~~~
> simple.c:20:18: warning: this statement may fall through 
> [-Wimplicit-fallthrough=]
>           case 2: c--;
>                   ~^~
> simple.c:22:9: note: here
>           case 3: c++;
>           ^~~~
> simple.c:22:18: warning: this statement may fall through 
> [-Wimplicit-fallthrough=]
>           case 3: c++;
>                   ~^~
> simple.c:24:9: note: here
>           case 4: z = c; break;
>           ^~~~
> 
> 
> How do I have to formulate these comments?  It's under mingw32, may that 
> be a problem?

There are a few important pieces missing from your message.

- The version of gcc you're using
- The exact command-line you used (flags, C vs C++ mode, etc)
- What you expected vs what happened

AFAICT, -Wimplicit-fallthrough is new with GCC 7, so I will assume
you are using 7.1

You seem to be looking for a way to silence the warning for specific
instances. Have a look here:

https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/

And according to the manual:

> C++17 provides a standard way to suppress the -Wimplicit-fallthrough
> warning using [[fallthrough]]; instead of the GNU attribute. In C++11
> or C++14 users can use [[gnu::fallthrough]];, which is a GNU
> extension. Instead of these attributes, it is also possible to add a
> fallthrough comment to silence the warning. The whole body of the C
> or C++ style comment should match the given regular expressions
> listed below. The option argument n specifies what kind of comments
> are accepted:
> 
>     -Wimplicit-fallthrough=0 disables the warning altogether.
>     -Wimplicit-fallthrough=1 matches .* regular expression, any comment is used as fallthrough comment.
>     -Wimplicit-fallthrough=2 case insensitively matches .*falls?[ \t-]*thr(ough|u).* regular expression.
>     -Wimplicit-fallthrough=3 case sensitively matches one of the following regular expressions:
>         -fallthrough
>         @fallthrough@
>         lint -fallthrough[ \t]*
>         [ \t.!]*(ELSE,? |INTENTIONAL(LY)? )?
>         FALL(S | |-)?THR(OUGH|U)[ \t.!]*(-[^\n\r]*)?
>         [ \t.!]*(Else,? |Intentional(ly)? )?
>         Fall((s | |-)[Tt]|t)hr(ough|u)[ \t.!]*(-[^\n\r]*)?
>         [ \t.!]*([Ee]lse,? |[Ii]ntentional(ly)? )?
>         fall(s | |-)?thr(ough|u)[ \t.!]*(-[^\n\r]*)? 
>     -Wimplicit-fallthrough=4 case sensitively matches one of the following regular expressions:
>         -fallthrough
>         @fallthrough@
>         lint -fallthrough[ \t]*
>         [ \t]*FALLTHR(OUGH|U)[ \t]* 
>     -Wimplicit-fallthrough=5 doesn’t recognize any comments as fallthrough comments, only attributes disable the warning. 
> 
> The comment needs to be followed after optional whitespace and other
> comments by case or default keywords or by a user label that precedes
> some case or default label.
> 
> switch (cond)
>   {
>   case 1:
>     bar (0);
>     /* FALLTHRU */
>   default:
>     ...
>   }
> 
> The -Wimplicit-fallthrough=3 warning is enabled by -Wextra. 

Regards.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux