C++ attribute: fallthrough (since C++17)

Indicates that the fall through from the previous case label is intentional and should not be diagnosed by a compiler that warns on fallthrough.

Syntax

[[fallthrough]]

Explanation

May only be applied to a null statement to create a fallthrough statement ([[fallthrough]];). A fallthrough statement may only be used in a switch statement, where the next statement to be executed is a statement with a case or default label for that switch statement. Indicates that the fall through from the previous case label is intentional and should not be diagnosed by a compiler that warns on fallthrough.

Example

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
  }
}

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/language/attributes/fallthrough