Title
[[fallthrough]] attribute and iteration statements
Status
cd5
Section
9.12.6 [dcl.attr.fallthrough]
Submitter
Mike Miller

Created on 2019-03-08.00:00:00 last changed 48 months ago

Messages

Date: 2020-12-15.00:00:00

Proposed resolution, April, 2019:

  1. Change 9.12.6 [dcl.attr.fallthrough] paragraph 1 as follows:

  2. The attribute-token fallthrough may be applied to a null statement (8.3 [stmt.expr]); such a statement is a fallthrough statement. The attribute-token fallthrough shall appear at most once in each attribute-list and no attribute-argument-clause shall be present. A fallthrough statement may only appear within an enclosing switch statement (8.5.3 [stmt.switch]). The next statement that would be executed after a fallthrough statement shall be a labeled statement whose label is a case label or default label for the same switch statement and, if the fallthrough statement is contained in an iteration statement, the next statement shall be part of the same execution of the substatement of the innermost enclosing iteration statement. The program is ill-formed if there is no such statement.
  3. Change the example in 9.12.6 [dcl.attr.fallthrough] paragraph 3 as follows:

  4. [Example:

      void f(int n) {
        void g(), h(), i();
        switch (n) {
        case 1:
        case 2:
          g();
          [[fallthrough]];
        case 3:              // warning on fallthrough discouraged
          do {
            [[fallthrough]]; // error: next statement is not part of the same substatement execution
          } while (false);
        case 6:
          do {
            [[fallthrough]]; // error: next statement is not part of the same substatement execution
          } while (n--);
        case 7:
          while (false) {
            [[fallthrough]]; // error: next statement is not part of the same substatement execution
          }
        case 5:
          h();
        case 4:              // implementation may warn on fallthrough
          i();
          [[fallthrough]];   // ill-formed
        }
      }
    

    end example]

Date: 2019-07-15.00:00:00

[Accepted as a DR at the July, 2019 meeting.]

According to 9.12.6 [dcl.attr.fallthrough] paragraph 1,

A fallthrough statement may only appear within an enclosing switch statement (8.5.3 [stmt.switch]). The next statement that would be executed after a fallthrough statement shall be a labeled statement whose label is a case label or default label for the same switch statement.

The meaning of “next statement that would be executed” is unclear with respect to the controlled substatement of an iteration statement. There is implementation divergence on an example like:

  void f(int n) {
    switch (n) {
      case 0:
        while (true)
          [[fallthrough]]; // Well-formed?
      case 1:
        break;
    }
  }
History
Date User Action Args
2020-12-15 00:00:00adminsetmessages: + msg6401
2019-03-08 00:00:00admincreate