diff --git a/tests/switch.c b/tests/switch.c index ad5691295..ebbec3a67 100644 --- a/tests/switch.c +++ b/tests/switch.c @@ -11,6 +11,7 @@ // CompoundStmt with 12 children. #include +#include #include "tests.h" void match_a_single_case() @@ -125,6 +126,42 @@ void fallthrough_several_midway_default() } } +void goto_label(bool use_goto) +{ + for (;;) { + switch (0) + { + case 3: + continue; + case 0: + if (use_goto) { + goto LABEL; + fail("code should not reach here"); + } else if (false) { + goto LABELX; + goto LABELY; + fail("code should not reach here"); + } + /* other comment */ + // some comment + /* fallthrough */ + LABELY: + case 4: + LABEL: + case 1: + pass(__func__); + break; + case 2: + ; + LABELX: + default: + fail("code should not reach here"); + break; + } + break; + } +} + void scoped_match_a_single_case() { switch (1) @@ -278,6 +315,51 @@ void scoped_fallthrough_several_midway_default() } } + +void scoped_goto_label(bool use_goto) +{ + for (;;) { + switch (0) + { + case 3: + { + continue; + } + case 0: + { + if (use_goto) { + goto LABEL; + fail("code should not reach here"); + } else if (false) { + goto LABELX; + goto LABELY; + fail("code should not reach here"); + } + /* other comment */ + // some comment + /* fallthrough */ + } + LABELY: {} + case 4: {} + LABEL: {} + case 1: + { + pass(__func__); + break; + } + case 2: + {} + LABELX: {} + default: + { + fail("code should not reach here"); + break; + } + } + break; + } +} + typedef struct I67 I67; struct I67{ int x,y; @@ -376,7 +458,7 @@ void switch_without_input() int main() { - plan(33); + plan(37); match_a_single_case(); fallthrough_to_next_case(); @@ -384,6 +466,8 @@ int main() match_default(); fallthrough_several_cases_including_default(); fallthrough_several_midway_default(); + goto_label(false); + goto_label(true); // For each of the tests above there will be identical cases that use scopes // for the case statements. @@ -393,6 +477,8 @@ int main() scoped_match_default(); scoped_fallthrough_several_cases_including_default(); scoped_fallthrough_several_midway_default(); + scoped_goto_label(false); + scoped_goto_label(true); switch_issue67(); empty_switch();