// // Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // fallthrough.cfa -- // // Author : Rob Schluntz // Created On : Wed Mar 14 10:06:25 2018 // Last Modified By : Peter A. Buhr // Last Modified On : Fri Jan 17 14:09:49 2025 // Update Count : 23 // #include void test(int choice) { choose ( choice ) { case 1: sout | "case 1"; fallthrough; case 2: sout | "case 2"; fallthrough; sout | "did not fallthrough"; if ( 7 ) fallthrough common2; fallthrough common1; case 3: sout | "case 3"; fallthrough default; fallthrough common1; common1: sout | "common1"; // break case 4: sout | "case 4"; fallthrough common2; case 5: sout | "case 5"; fallthrough common2; fallthrough default; case 6: sout | "case 6"; fallthrough common2; common2: sout | "common2"; // break default: sout | "default"; fallthrough; } // choose sout | nl; switch ( choice ) { case 1: sout | "case 1"; switch ( choice ) { case 1: sout | "case 1"; for ( int i = 0; i < 4; i += 1 ) { sout | i; if ( i == 2 ) fallthrough common; } // for } // switch break; case 5: sout | "case 5"; if ( choice == 5 ) { if ( choice != 5 ) { sout | "error"; } else { sout | "check"; fallthrough common; } // if } // if common: sout | "common"; fallthrough; break; default: sout | "default"; fallthrough; } // switch #if ERR1 // ERROR: fallthrough must be enclosed in switch or choose fallthrough; // ERROR: fallthrough must be enclosed in switch or choose fallthrough common4; // ERROR: fallthrough must be enclosed in switch or choose fallthrough default; choose ( 3 ) { case 2: for () { choose ( 2 ) { case 1: // ERROR: default is later, but in a different switch fallthrough default; // ERROR: common3 is later, but not at the same level as a case clause fallthrough common3; } common3: ; } // for default: case 1: common4: // ERROR: attempt to jump up with fallthrough if ( 7 ) fallthrough common4; // ERROR: attempt to jump up with fallthrough fallthrough default; } // choose #endif } int main() { test( 1 ); sout | nl; test( 5 ); } // Local Variables: // // tab-width: 4 // // compile-command: "cfa fallthrough.cfa" // // End: //