Debian Codegraph @

gcc/testsuite/g++.old-deja/g++.law/cvt7.C

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