https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85714

            Bug ID: 85714
           Summary: -Wimplicit-fallthrough and nested exhaustive switch
                    statements with enum classes and return
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: thomas.o...@pdv-fs.de
  Target Milestone: ---

Nesting enum class switch statements which are exhaustive and whose cases all
return produces a false positive -Werror=implicit-fallthrough warning:

$ ~/gcc/8.1.0/bin/g++ -Wall -Wextra -c switch_fallthrough.cpp -Werror
switch_fallthrough.cpp: In function 'int example(Foo, Bar)':
switch_fallthrough.cpp:8:7: error: this statement may fall through
[-Werror=implicit-fallthrough=]
       switch(b) {
       ^~~~~~
switch_fallthrough.cpp:13:5: note: here
     case Foo::E2:
     ^~~~


Uncommenting the [[fallthrough]]; fixes this, but should not be required since
no fallthrough can happen.

Related, the last return -1 in the function should not be required since the
outer switch is also exhaustive.



enum class Foo { E1, E2 };
enum class Bar { A, B }; 

int example(Foo f, Bar b)
{
  switch(f) {
    case Foo::E1:
      switch(b) {
         case Bar::A:  return 1;
         case Bar::B:  return 2;
      }
///    [[fallthrough]]; // -Wimplicit-fallthrough -- new in gcc 8.1
    case Foo::E2:
      switch(b) {
         case Bar::A:  return 3;
         case Bar::B:  return 4;
      }

  }
  return -1; // -Wreturn-type -- already in gcc 7.3, should not be required
}

Reply via email to