Bug 91432 - gcc -Wimplicit-fallthrough does not warn when fallthrough to break;
Summary: gcc -Wimplicit-fallthrough does not warn when fallthrough to break;
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-13 07:40 UTC by Joe Perches
Modified: 2020-06-04 17:45 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joe Perches 2019-08-13 07:40:57 UTC
This code does not emit a fallthrough warning:

int foo(int i)
{
  switch (i) {
  case 1:
    i = 0;
  default:
    break;
  }
  return i;
}

Basically any case block that falls through to another
block of just a break statement does not get a warning.

Is this a defect or what was the logic behind this decision?
Comment 1 Marc Glisse 2019-08-13 08:16:07 UTC
The warning basically says "you may have forgotten 'break;'". If it falls through to break anyway, what difference does it make if I add a redundant break?
Comment 2 Martin Liška 2020-01-27 13:56:39 UTC
I would close this as invalid.
Comment 3 Nick Desaulniers 2020-06-04 17:45:25 UTC
Isn't this still an implicit fallthrough, though?  It may not "be a bug," but that's why warnings are not errors; they may not result in "bugs."

The issue is that Clang will warn in this case, so developers get confused about writing compiler-portable code with intentional fallthrough vs being warned about unintentional fallthrough.

Why shouldn't developers annotate that the implicit fallthrough from `case 1` to `default` was intentional, making it explicit?