Mike Stump | 4617191 | 2010-01-23 20:12:18 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unreachable-code |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2 | |
Mike Stump | d1969d8 | 2009-07-22 00:43:08 +0000 | [diff] [blame] | 3 | void test1() { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 4 | { ; { ;;}} ;; |
| 5 | } |
| 6 | |
Mike Stump | d1969d8 | 2009-07-22 00:43:08 +0000 | [diff] [blame] | 7 | void test2() { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 8 | if (0) { if (1) {} } else { } |
| 9 | |
| 10 | do { } while (0); |
| 11 | |
| 12 | while (0) while(0) do ; while(0); |
| 13 | |
Daniel Dunbar | 4dabe96 | 2009-08-01 06:07:15 +0000 | [diff] [blame] | 14 | for ((void)0;0;(void)0) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 15 | for (;;) |
Daniel Dunbar | 4dabe96 | 2009-08-01 06:07:15 +0000 | [diff] [blame] | 16 | for ((void)9;0;(void)2) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 17 | ; |
Daniel Dunbar | 4dabe96 | 2009-08-01 06:07:15 +0000 | [diff] [blame] | 18 | for (int X = 0; 0; (void)0); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 19 | } |
| 20 | |
Mike Stump | d1969d8 | 2009-07-22 00:43:08 +0000 | [diff] [blame] | 21 | void test3() { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 22 | switch (0) { |
| 23 | |
| 24 | case 4: |
| 25 | if (0) { |
| 26 | case 6: ; |
| 27 | } |
| 28 | default: |
| 29 | ; |
| 30 | } |
| 31 | } |
| 32 | |
Mike Stump | d1969d8 | 2009-07-22 00:43:08 +0000 | [diff] [blame] | 33 | void test4() { |
Dmitri Gribenko | 625bb56 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 34 | if (0); // expected-warning {{if statement has empty body}} expected-note {{put the semicolon on a separate line to silence this warning}} |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 35 | |
| 36 | int X; // declaration in a block. |
| 37 | |
Dmitri Gribenko | 625bb56 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 38 | foo: if (0); // expected-warning {{if statement has empty body}} expected-note {{put the semicolon on a separate line to silence this warning}} |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | typedef int t; |
| 42 | void test5() { |
Dmitri Gribenko | 625bb56 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 43 | if (0); // expected-warning {{if statement has empty body}} expected-note {{put the semicolon on a separate line to silence this warning}} |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 44 | |
Chris Lattner | a668e8e | 2008-11-13 18:42:17 +0000 | [diff] [blame] | 45 | t x = 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 46 | |
Dmitri Gribenko | 625bb56 | 2012-02-14 22:14:32 +0000 | [diff] [blame] | 47 | if (0); // expected-warning {{if statement has empty body}} expected-note {{put the semicolon on a separate line to silence this warning}} |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Chris Lattner | 1950440 | 2008-11-13 18:52:53 +0000 | [diff] [blame] | 50 | |
| 51 | void test6(void) { |
| 52 | do |
| 53 | . // expected-error {{expected expression}} |
| 54 | while (0); |
| 55 | } |
| 56 | |
Chris Lattner | 7b3684a | 2009-06-14 00:23:56 +0000 | [diff] [blame] | 57 | int test7() { |
| 58 | return 4 // expected-error {{expected ';' after return statement}} |
| 59 | } |
Argyrios Kyrtzidis | b57c757 | 2010-03-31 00:37:59 +0000 | [diff] [blame] | 60 | |
| 61 | void test8() { |
| 62 | // Should not skip '}' and produce a "expected '}'" error. |
| 63 | undecl // expected-error {{use of undeclared identifier 'undecl'}} |
| 64 | } |
Richard Smith | 4b08242 | 2012-09-18 00:52:05 +0000 | [diff] [blame] | 65 | |
| 66 | int test9() { |
| 67 | int T[] = {1, 2, }; |
| 68 | |
| 69 | int X; |
| 70 | X = 0, // expected-error {{expected ';' after expression}} |
| 71 | { |
| 72 | } |
| 73 | |
| 74 | X = 0, // expected-error {{expected ';' after expression}} |
| 75 | if (0) |
| 76 | ; |
| 77 | |
| 78 | return 4, // expected-error {{expected ';' after return statement}} |
| 79 | } |