Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Chris Lattner | 8a87e57 | 2007-07-23 17:05:23 +0000 | [diff] [blame] | 2 | void f (int z) { |
| 3 | while (z) { |
Chris Lattner | 0471f5b | 2007-08-23 18:29:20 +0000 | [diff] [blame] | 4 | default: z--; // expected-error {{statement not in switch}} |
Chris Lattner | 8a87e57 | 2007-07-23 17:05:23 +0000 | [diff] [blame] | 5 | } |
| 6 | } |
| 7 | |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 8 | void foo(int X) { |
| 9 | switch (X) { |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 10 | case 42: ; // expected-note {{previous case}} |
Chris Lattner | 0471f5b | 2007-08-23 18:29:20 +0000 | [diff] [blame] | 11 | case 5000000000LL: // expected-warning {{overflow}} |
| 12 | case 42: // expected-error {{duplicate case value}} |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 13 | ; |
Chris Lattner | 6efc4d3 | 2007-08-23 17:48:14 +0000 | [diff] [blame] | 14 | |
Chris Lattner | 0471f5b | 2007-08-23 18:29:20 +0000 | [diff] [blame] | 15 | case 100 ... 99: ; // expected-warning {{empty case range}} |
| 16 | |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 17 | case 43: ; // expected-note {{previous case}} |
Chris Lattner | 0471f5b | 2007-08-23 18:29:20 +0000 | [diff] [blame] | 18 | case 43 ... 45: ; // expected-error {{duplicate case value}} |
| 19 | |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 20 | case 100 ... 20000:; // expected-note {{previous case}} |
Chris Lattner | 0471f5b | 2007-08-23 18:29:20 +0000 | [diff] [blame] | 21 | case 15000 ... 40000000:; // expected-error {{duplicate case value}} |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 22 | } |
| 23 | } |
| 24 | |
Chris Lattner | f334850 | 2007-08-23 14:29:07 +0000 | [diff] [blame] | 25 | void test3(void) { |
Chris Lattner | 0471f5b | 2007-08-23 18:29:20 +0000 | [diff] [blame] | 26 | // empty switch; |
Chris Lattner | f334850 | 2007-08-23 14:29:07 +0000 | [diff] [blame] | 27 | switch (0); |
| 28 | } |
| 29 | |
Anders Carlsson | 51fe996 | 2008-11-22 21:04:56 +0000 | [diff] [blame] | 30 | extern int g(); |
| 31 | |
| 32 | void test4() |
| 33 | { |
| 34 | switch (1) { |
| 35 | case 0 && g(): |
| 36 | case 1 || g(): |
| 37 | break; |
| 38 | } |
| 39 | |
| 40 | switch(1) { |
Anders Carlsson | d3a61d5 | 2008-12-01 02:13:02 +0000 | [diff] [blame] | 41 | case g(): // expected-error {{expression is not an integer constant expression}} |
| 42 | case 0 ... g(): // expected-error {{expression is not an integer constant expression}} |
Anders Carlsson | 51fe996 | 2008-11-22 21:04:56 +0000 | [diff] [blame] | 43 | break; |
| 44 | } |
| 45 | |
| 46 | switch (1) { |
| 47 | case 0 && g() ... 1 || g(): |
| 48 | break; |
| 49 | } |
Anders Carlsson | 6dde0d5 | 2008-11-22 21:50:49 +0000 | [diff] [blame] | 50 | |
| 51 | switch (1) { |
Anders Carlsson | d3a61d5 | 2008-12-01 02:13:02 +0000 | [diff] [blame] | 52 | case g() && 0: // expected-error {{expression is not an integer constant expression}} // expected-note {{subexpression not valid in an integer constant expression}} |
Anders Carlsson | 6dde0d5 | 2008-11-22 21:50:49 +0000 | [diff] [blame] | 53 | break; |
| 54 | } |
| 55 | |
| 56 | switch (1) { |
Anders Carlsson | d3a61d5 | 2008-12-01 02:13:02 +0000 | [diff] [blame] | 57 | case 0 ... g() || 1: // expected-error {{expression is not an integer constant expression}} // expected-note {{subexpression not valid in an integer constant expression}} |
Anders Carlsson | 6dde0d5 | 2008-11-22 21:50:49 +0000 | [diff] [blame] | 58 | break; |
| 59 | } |
Anders Carlsson | 51fe996 | 2008-11-22 21:04:56 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 62 | void test5(int z) { |
| 63 | switch(z) { |
| 64 | default: // expected-note {{previous case defined here}} |
| 65 | default: // expected-error {{multiple default labels in one switch}} |
| 66 | break; |
| 67 | } |
| 68 | } |
| 69 | |
Chris Lattner | 5f04881 | 2009-10-16 16:45:22 +0000 | [diff] [blame] | 70 | void test6() { |
| 71 | const char ch = 'a'; |
| 72 | switch(ch) { |
| 73 | case 1234: // expected-warning {{overflow converting case value}} |
| 74 | break; |
| 75 | } |
| 76 | } |
Douglas Gregor | be724ba | 2009-11-25 06:20:02 +0000 | [diff] [blame] | 77 | |
| 78 | // PR5606 |
Douglas Gregor | 539c5c3 | 2010-01-07 00:31:29 +0000 | [diff] [blame^] | 79 | int f0(int var) { // expected-note{{'var' declared here}} |
Douglas Gregor | be724ba | 2009-11-25 06:20:02 +0000 | [diff] [blame] | 80 | switch (va) { // expected-error{{use of undeclared identifier 'va'}} |
| 81 | case 1: |
| 82 | break; |
| 83 | case 2: |
| 84 | return 1; |
| 85 | } |
| 86 | return 2; |
| 87 | } |