Debian Codegraph @

gcc/testsuite/g++.dg/cpp0x/auto2.C

raw
1 // Positive test for auto
2 // { dg-do run { target c++11 } }
3
4 #include <typeinfo>
5 extern "C" void abort();
6
7 int f() { return 0; }
8
9 struct A
10 {
11 int i;
12 int f() { return 0; }
13 A operator+(A a) { return a; }
14 };
15
16 template <class T>
17 void g(T t)
18 {
19 auto x = t+t;
20 if (typeid(x) != typeid(t+t))
21 abort();
22
23 auto p = new auto(&t);
24 if (typeid(p) != typeid(T**))
25 abort();
26 }
27
28 int main()
29 {
30 auto i = 42;
31 if (typeid (i) != typeid (int))
32 abort();
33
34 auto *p = &i;
35 if (typeid (p) != typeid (int*))
36 abort();
37
38 auto *p2 = &p;
39 if (typeid (p2) != typeid (int**))
40 abort();
41
42 auto (*fp)() = f;
43 if (typeid (fp) != typeid (int (*)()))
44 abort();
45
46 auto A::* pm = &A::i;
47 if (typeid (pm) != typeid (int A::*))
48 abort();
49
50 auto (A::*pmf)() = &A::f;
51 if (typeid (pmf) != typeid (int (A::*)()))
52 abort();
53
54 g(42);
55 g(10.f);
56 g(A());
57
58 auto *p3 = new auto (i);
59 if (typeid (p3) != typeid (int*))
60 abort();
61
62 for (auto idx = i; idx != 0; idx = 0);
63 while (auto idx = 0);
64 if (auto idx = 1);
65
66 switch (auto s = i)
67 {
68 case 42:
69 break;
70 }
71
72 auto j = 42, k = 24;
73 return 0;
74 }