• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wswitch-enum %s
2 
test()3 void test() {
4   bool x = true;
5   switch (x) { // expected-warning {{bool}}
6     case 0:
7       break;
8   }
9 
10   int n = 3;
11   switch (n && true) { // expected-warning {{bool}}
12     case 1:
13       break;
14   }
15 }
16 
17 // PR5518
18 struct A {
19   operator int(); // expected-note{{conversion to integral type}}
20 };
21 
x()22 void x() {
23   switch(A()) {
24   }
25 }
26 
27 enum E { e1, e2 };
28 struct B : A {
29   operator E() const; // expected-note{{conversion to enumeration type}}
30 };
31 
x2()32 void x2() {
33   switch (B()) { // expected-error{{multiple conversions}}
34   }
35 }
36 
37 struct C; // expected-note{{forward declaration}}
38 
x3(C & c)39 void x3(C &c) {
40   switch (c) { // expected-error{{incomplete class type}}
41   }
42 }
43 
44 namespace test3 {
45   enum En { A, B, C };
foo()46   template <En how> void foo() {
47     int x = 0, y = 5;
48 
49     switch (how) { //expected-warning {{no case matching constant switch condition '2'}}
50     case A: x *= y; break;
51     case B: x += y; break;
52     // No case for C, but it's okay because we have a constant condition.
53     }
54   }
55 
56   template void foo<A>();
57   template void foo<B>();
58   template void foo<C>(); //expected-note {{in instantiation}}
59 }
60 
61 // PR9304 and rdar://9045501
click_check_header_sizes()62 void click_check_header_sizes() {
63   switch (0 == 8) {  // expected-warning {{switch condition has boolean value}}
64   case 0: ;
65   }
66 }
67