Changes in / [f107afe:1842167]


Ignore:
Files:
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/MultiLevelExit.cpp

    rf107afe r1842167  
    8484        bool isFallDefaultTarget() const { return kind == SwitchStmtK; }
    8585
    86         // Check if this entry can be the target of an unlabelled break.
    87         bool isUnlabelledBreakTarget() const { return kind <= WhileDoStmtK || kind == SwitchStmtK; }
    88 
    8986        // These routines set a target as being "used" by a BranchStmt
    9087        Label useContExit() { assert( kind <= WhileDoStmtK ); return useTarget(secondTarget); }
     
    117114bool isFallthroughDefaultTarget( const Entry & entry ) {
    118115        return entry.isFallDefaultTarget();
    119 }
    120 
    121 bool isUnlabelledBreakTarget( const Entry & entry ) {
    122         return entry.isUnlabelledBreakTarget();
    123116}
    124117
     
    254247        case BranchStmt::Break: {
    255248                bool isContinue = stmt->kind == BranchStmt::Continue;
    256                 // Handle unlabeled continue.
    257                 if ( isContinue && stmt->target.empty() ) {
    258                         targetEntry = findEnclosingControlStructure( isContinueTarget );
    259                         if ( targetEntry == enclosing_control_structures.rend() ) {
    260                                 SemanticError( stmt->location,
    261                                                "\"continue\" outside a loop" );
     249                // Handle unlabeled break and continue.
     250                if ( stmt->target.empty() ) {
     251                        if ( isContinue ) {
     252                                targetEntry = findEnclosingControlStructure( isContinueTarget );
     253                        } else {
     254                                if ( enclosing_control_structures.empty() ) {
     255                                          SemanticError( stmt->location,
     256                                                                         "\"break\" outside a loop, \"switch\", or labelled block" );
     257                                }
     258                                targetEntry = findEnclosingControlStructure( isBreakTarget );
    262259                        }
    263                 // Handle unlabeled break.
    264                 } else if ( stmt->target.empty() ) {
    265                         targetEntry = findEnclosingControlStructure( isUnlabelledBreakTarget );
    266                         if ( targetEntry == enclosing_control_structures.rend() ) {
    267                                 SemanticError( stmt->location,
    268                                                "\"break\" outside a loop or \"switch\"" );
    269                         }
    270                 // Handle labeled break and continue.
     260                        // Handle labeled break and continue.
    271261                } else {
    272262                        // Lookup label in table to find attached control structure.
     
    275265                                          return entry.stmt == targetStmt;
    276266                                } );
    277                         // Ensure that selected target is valid.
    278                         if ( targetEntry == enclosing_control_structures.rend()
    279                                         || ( isContinue ? !isContinueTarget( *targetEntry ) : !isBreakTarget( *targetEntry ) ) ) {
    280                                 SemanticError( stmt->location, toString( (isContinue ? "\"continue\"" : "\"break\""),
    281                                                " target must be an enclosing ", (isContinue ? "loop: " : "control structure: "),
    282                                                stmt->originalTarget ) );
    283                         }
     267                }
     268                // Ensure that selected target is valid.
     269                if ( targetEntry == enclosing_control_structures.rend() || ( isContinue && ! isContinueTarget( *targetEntry ) ) ) {
     270                        SemanticError( stmt->location, toString( (isContinue ? "\"continue\"" : "\"break\""),
     271                                                        " target must be an enclosing ", (isContinue ? "loop: " : "control structure: "),
     272                                                        stmt->originalTarget ) );
    284273                }
    285274                break;
  • tests/exceptions/.expect/try-ctrl-flow.txt

    rf107afe r1842167  
    1 exceptions/try-ctrl-flow.cfa:7:1 error: "break" outside a loop or "switch"
    2 exceptions/try-ctrl-flow.cfa:15:1 error: "break" outside a loop or "switch"
    3 exceptions/try-ctrl-flow.cfa:23:1 error: "break" outside a loop or "switch"
    4 exceptions/try-ctrl-flow.cfa:31:1 error: "continue" outside a loop
     1exceptions/try-ctrl-flow.cfa:7:1 error: "break" outside a loop, "switch", or labelled block
     2exceptions/try-ctrl-flow.cfa:15:1 error: "break" outside a loop, "switch", or labelled block
     3exceptions/try-ctrl-flow.cfa:23:1 error: "break" outside a loop, "switch", or labelled block
     4exceptions/try-ctrl-flow.cfa:31:1 error: "continue" target must be an enclosing loop:
    55exceptions/try-ctrl-flow.cfa:48:1 error: "break" target must be an enclosing control structure: mainLoop
    66exceptions/try-ctrl-flow.cfa:56:1 error: "continue" target must be an enclosing loop: mainLoop
    7 exceptions/try-ctrl-flow.cfa:65:1 error: "break" outside a loop or "switch"
    8 exceptions/try-ctrl-flow.cfa:76:1 error: "break" outside a loop or "switch"
     7exceptions/try-ctrl-flow.cfa:65:1 error: "break" outside a loop, "switch", or labelled block
     8exceptions/try-ctrl-flow.cfa:76:1 error: "break" outside a loop, "switch", or labelled block
    99exceptions/try-ctrl-flow.cfa:87:1 error: "fallthrough" must be enclosed in a "switch" or "choose"
    1010exceptions/try-ctrl-flow.cfa:98:1 error: "break" target must be an enclosing control structure: mainBlock
     
    1313exceptions/try-ctrl-flow.cfa:133:1 error: "return" may not appear in a finally clause
    1414exceptions/try-ctrl-flow.cfa:139:1 error: "return" may not appear in a finally clause
    15 exceptions/try-ctrl-flow.cfa:148:1 error: "break" outside a loop or "switch"
     15exceptions/try-ctrl-flow.cfa:148:1 error: "break" outside a loop, "switch", or labelled block
    1616exceptions/try-ctrl-flow.cfa:159:1 error: "return" may not appear in a try statement with a catch clause
    1717exceptions/try-ctrl-flow.cfa:187:1 error: "return" may not appear in a catchResume clause
Note: See TracChangeset for help on using the changeset viewer.