Namespaces
Variants
Views
Actions

cpp/language/attributes/fallthrough

From cppreference.com
< cpp‎ | language‎ | attributes
Revision as of 04:21, 24 June 2018 by Fruderica (Talk | contribs)

Template:cpp/attribute/title Template:cpp/attribute/navbar

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

Appears in a switch statement on a line of its own (technically as an attribute of a null statement), immediately before a case label. 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
      i();
      [[fallthrough]]; // ill­formed, not before a case label
  }
}