blob: 54240dcc305f619fe976e47aab44caaf95314a59 [file] [log] [blame]
John McCall0fb97082010-05-18 03:19:21 +00001// RUN: %clang_cc1 -fsyntax-only -verify -Wswitch-enum %s
Edward O'Callaghan12356b12009-10-17 19:32:54 +00002
3void test() {
4 bool x = true;
5 switch (x) { // expected-warning {{bool}}
6 case 0:
7 break;
8 }
9
10 int n = 3;
Chris Lattner90a8f272010-07-13 19:41:32 +000011 switch (n && 1) { // expected-warning {{bool}} \
12 // expected-warning {{use of logical && with constant operand}}
Edward O'Callaghan12356b12009-10-17 19:32:54 +000013 case 1:
14 break;
15 }
16}
Douglas Gregor84fb9c02009-11-23 13:46:08 +000017
18// PR5518
19struct A {
20 operator int(); // expected-note{{conversion to integral type}}
21};
22
23void x() {
24 switch(A()) {
25 }
26}
27
28enum E { e1, e2 };
29struct B : A {
30 operator E() const; // expected-note{{conversion to enumeration type}}
31};
32
33void x2() {
34 switch (B()) { // expected-error{{multiple conversions}}
35 }
36}
Douglas Gregorf21bac62009-11-23 13:53:21 +000037
38struct C; // expected-note{{forward declaration}}
39
40void x3(C &c) {
41 switch (c) { // expected-error{{incomplete class type}}
42 }
43}
John McCall0fb97082010-05-18 03:19:21 +000044
45namespace test3 {
46 enum En { A, B, C };
47 template <En how> void foo() {
48 int x = 0, y = 5;
49
50 switch (how) { //expected-warning {{no case matching constant switch condition '2'}}
51 case A: x *= y; break;
52 case B: x += y; break;
53 // No case for C, but it's okay because we have a constant condition.
54 }
55 }
56
57 template void foo<A>();
58 template void foo<B>();
59 template void foo<C>(); //expected-note {{in instantiation}}
60}