source: tests/fallthrough.cfa@ ad72c8b

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr no_list persistent-indexer pthread-emulation qualifiedEnum
Last change on this file since ad72c8b was 200fcb3, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

add auto newline to sout, change endl to nl

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[e2c70ab]1//
2// Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[dc8511c]7// fallthrough.cfa --
[e2c70ab]8//
9// Author : Rob Schluntz
10// Created On : Wed Mar 14 10:06:25 2018
[13f5a70]11// Last Modified By : Peter A. Buhr
[200fcb3]12// Last Modified On : Tue Dec 4 21:36:14 2018
13// Update Count : 17
[e2c70ab]14//
15
[303d866]16#include <fstream.hfa>
17
[e2c70ab]18void test(int choice) {
19 choose ( choice ) {
20 case 1:
[200fcb3]21 sout | "case 1";
[e2c70ab]22 fallthru;
23 case 2:
[200fcb3]24 sout | "case 2";
[e2c70ab]25 fallthru;
[200fcb3]26 sout | "did not fallthru";
[e2c70ab]27 if ( 7 ) fallthru common2;
28 fallthru common1;
29 case 3:
[200fcb3]30 sout | "case 3";
[e2c70ab]31 fallthru default;
32 fallthru common1;
33 common1:
[200fcb3]34 sout | "common1";
[13f5a70]35 // break
[e2c70ab]36 case 4:
[200fcb3]37 sout | "case 4";
[e2c70ab]38 fallthru common2;
39 case 5:
[200fcb3]40 sout | "case 5";
[e2c70ab]41 fallthru common2;
42 fallthru default;
43 case 6:
[200fcb3]44 sout | "case 6";
[e2c70ab]45 fallthru common2;
46 common2:
[200fcb3]47 sout | "common2";
[13f5a70]48 // break
[e2c70ab]49 default:
[200fcb3]50 sout | "default";
[e2c70ab]51 fallthru;
52 }
53
[200fcb3]54 sout | nl;
[13f5a70]55
56 switch ( choice ) {
57 case 1:
[200fcb3]58 sout | "case 1";
[13f5a70]59 switch ( choice ) {
60 case 1:
[200fcb3]61 sout | "case 1";
[13f5a70]62 for ( int i = 0; i < 4; i += 1 ) {
63 printf("%d\n", i);
64 if ( i == 2 ) fallthru common;
65 } // for
66 } // switch
67 break;
68 case 5:
[200fcb3]69 sout | "case 5";
[13f5a70]70 if ( choice == 5 ) {
71 if ( choice != 5 ) {
[200fcb3]72 sout | "error";
[13f5a70]73 } else {
[200fcb3]74 sout | "check";
[13f5a70]75 fallthru common;
76 } // if
77 } // if
78 common:
79 printf( "common\n" );
80 fallthru;
81 break;
82 default:
83 printf( "default\n" );
84 fallthru;
85 } // switch
86
[e2c70ab]87#if ERR1
88 // ERROR: fallthrough must be enclosed in switch or choose
89 fallthru;
90 // ERROR: fallthrough must be enclosed in switch or choose
91 fallthru common4;
92 // ERROR: fallthrough must be enclosed in switch or choose
93 fallthru default;
94 choose ( 3 ) {
95 case 2:
[adb6b30f]96 for () {
[e2c70ab]97 choose ( 2 ) {
98 case 1:
99 // ERROR: default is later, but in a different switch
100 fallthru default;
101 // ERROR: common3 is later, but not at the same level as a case clause
102 fallthru common3;
103 }
104 common3: ;
105 }
106 default:
107 case 1:
108 common4:
109 // ERROR: attempt to jump up with fallthrough
110 if ( 7 ) fallthru common4;
111 // ERROR: attempt to jump up with fallthrough
112 fallthru default;
113 }
114#endif
115}
116
117int main() {
[303d866]118 test( 1 );
[200fcb3]119 sout | nl;
[303d866]120 test( 5 );
[e2c70ab]121}
122
123// Local Variables: //
124// tab-width: 4 //
[dc8511c]125// compile-command: "cfa fallthrough.cfa" //
[e2c70ab]126// End: //
Note: See TracBrowser for help on using the repository browser.