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

            Bug ID: 87230
           Summary: GCC should warn if [[fallthrough]] is used in the last
                    case in a switch
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: david.bolvansky at gmail dot com
  Target Milestone: ---

void f(int n) {
  void g(), h(), i();
  switch (n) {
    case 1:
    case 2:
      g();
     [[fallthrough]];
    case 3: // no warning on fallthrough
      h();
    case 4: // compiler may warn on fallthrough
      if(n < 3) {
          i();
          [[fallthrough]]; // OK
      }
      else {
          return;
      }
    case 5:
      [[fallthrough]]; // ill-formed, no subsequent case or default label
  }
}

gcc -O3 -std=c++17 -Wall -Werror -> no errors

clang -O3 -std=c++17 -Wall -Werror ->
<source>:24:7: error: fallthrough annotation does not directly precede switch
label

      [[fallthrough]]; // ill-formed, no subsequent case or default label

      ^

Reply via email to