| Richard Smith | 1002d10 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s | 
| Edward O'Callaghan | 93135aa | 2009-10-17 19:32:54 +0000 | [diff] [blame] | 2 |  | 
|  | 3 | void test() { | 
|  | 4 | bool x = true; | 
|  | 5 | switch (x) { // expected-warning {{bool}} | 
|  | 6 | case 0: | 
|  | 7 | break; | 
|  | 8 | } | 
|  | 9 |  | 
|  | 10 | int n = 3; | 
| Chandler Carruth | e54ff6c | 2011-05-31 05:41:42 +0000 | [diff] [blame] | 11 | switch (n && true) { // expected-warning {{bool}} | 
| Edward O'Callaghan | 93135aa | 2009-10-17 19:32:54 +0000 | [diff] [blame] | 12 | case 1: | 
|  | 13 | break; | 
|  | 14 | } | 
|  | 15 | } | 
| Douglas Gregor | d0c22e0 | 2009-11-23 13:46:08 +0000 | [diff] [blame] | 16 |  | 
|  | 17 | // PR5518 | 
|  | 18 | struct A { | 
|  | 19 | operator int(); // expected-note{{conversion to integral type}} | 
|  | 20 | }; | 
|  | 21 |  | 
|  | 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 |  | 
|  | 32 | void x2() { | 
|  | 33 | switch (B()) { // expected-error{{multiple conversions}} | 
|  | 34 | } | 
|  | 35 | } | 
| Douglas Gregor | 378e192 | 2009-11-23 13:53:21 +0000 | [diff] [blame] | 36 |  | 
|  | 37 | struct C; // expected-note{{forward declaration}} | 
|  | 38 |  | 
|  | 39 | void x3(C &c) { | 
|  | 40 | switch (c) { // expected-error{{incomplete class type}} | 
|  | 41 | } | 
|  | 42 | } | 
| John McCall | d3dfbd6 | 2010-05-18 03:19:21 +0000 | [diff] [blame] | 43 |  | 
|  | 44 | namespace test3 { | 
|  | 45 | enum En { A, B, C }; | 
|  | 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 | } | 
| Chris Lattner | abcf38a | 2011-02-24 07:31:28 +0000 | [diff] [blame] | 60 |  | 
|  | 61 | // PR9304 and rdar://9045501 | 
|  | 62 | void click_check_header_sizes() { | 
|  | 63 | switch (0 == 8) {  // expected-warning {{switch condition has boolean value}} | 
|  | 64 | case 0: ; | 
|  | 65 | } | 
|  | 66 | } | 
| Richard Smith | 1002d10 | 2012-02-17 01:35:32 +0000 | [diff] [blame] | 67 |  | 
|  | 68 | void local_class(int n) { | 
|  | 69 | for (;;) switch (n) { | 
|  | 70 | case 0: | 
|  | 71 | struct S { | 
|  | 72 | void f() { | 
|  | 73 | case 1: // expected-error {{'case' statement not in switch statement}} | 
|  | 74 | break; // expected-error {{'break' statement not in loop or switch statement}} | 
|  | 75 | default: // expected-error {{'default' statement not in switch statement}} | 
|  | 76 | continue; // expected-error {{'continue' statement not in loop statement}} | 
|  | 77 | } | 
|  | 78 | }; | 
|  | 79 | S().f(); | 
|  | 80 | []{ | 
|  | 81 | case 2: // expected-error {{'case' statement not in switch statement}} | 
|  | 82 | break; // expected-error {{'break' statement not in loop or switch statement}} | 
|  | 83 | default: // expected-error {{'default' statement not in switch statement}} | 
|  | 84 | continue; // expected-error {{'continue' statement not in loop statement}} | 
|  | 85 | }(); | 
|  | 86 | } | 
|  | 87 | } | 
| Richard Smith | ccc1181 | 2013-05-21 19:05:48 +0000 | [diff] [blame] | 88 |  | 
|  | 89 | namespace Conversion { | 
|  | 90 | struct S { | 
|  | 91 | explicit operator int(); // expected-note {{conversion}} | 
|  | 92 | }; | 
|  | 93 | template<typename T> void f(T t) { | 
|  | 94 | switch (t) { // expected-error {{explicit conversion}} | 
|  | 95 | case 0: | 
|  | 96 | return; | 
|  | 97 | default: | 
|  | 98 | break; | 
|  | 99 | } | 
|  | 100 | } | 
|  | 101 | template void f(S); // expected-note {{instantiation of}} | 
|  | 102 | } |