1 // { dg-do run } 2 // GROUPS passed conversions 3 // cvt file 4 // From: krste@icsi.berkeley.edu (Krste Asanovic) 5 // Date: Mon, 24 Aug 92 19:05:10 PDT 6 // Message-Id: <9208250205.AA26351@icsib43.ICSI.Berkeley.EDU> 7 // Subject: implicit int. convs. from member refs. in switch expressions 8 9 #include <cstdio> 10 11 class A 12 { 13 public: A(int j)14 A(int j) { i = j; } A(A & a)15 A(A& a) { i = a.i; } 16 operator int() { return i; } 17 assign(int v)18 void assign(int v) { i = v; } 19 int i; 20 }; 21 22 class B 23 { 24 public: B(A & inArg)25 B(A& inArg) : in(inArg), out(0) {} 26 27 A& in; 28 A out; 29 30 void run(); 31 }; 32 33 void run()34B::run() 35 { 36 // I get a "switch quantity not an integer" error for this statement. 37 switch (in) 38 // Replacing above with "switch (int(in))" removes the error. 39 { 40 case 0: 41 out = 1; 42 break; 43 default: 44 out = 0; 45 break; 46 } 47 } 48 main()49int main() 50 { 51 A a(1); 52 53 A& ar = a; 54 55 A& ar2 = ar; 56 57 // ....but no errors for this switch statement. 58 switch (ar2) 59 { 60 case 1: 61 std::printf ("PASS\n"); 62 break; 63 default: 64 { std::printf ("FAIL\n"); return 1; } 65 } 66 67 B b(a); 68 a.assign(3); 69 b.run(); 70 a.assign(0); 71 b.run(); 72 73 return 0; 74 } 75 76 77 78 79 80 81 82