summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp0x/auto2.C
blob: 626e9e245d4862ac6de64c5d8eb1975bb27c83f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Positive test for auto
// { dg-do run }
// { dg-options "-std=c++0x" }

#include <typeinfo>
extern "C" void abort();

int f() {}

struct A
{
  int i;
  int f() {}
  A operator+(A a) { return a; }
};

template <class T>
void g(T t)
{
  auto x = t+t;
  if (typeid(x) != typeid(t+t))
    abort();

  auto p = new auto(&t);
  if (typeid(p) != typeid(T**))
    abort();
}

int main()
{
  auto i = 42;
  if (typeid (i) != typeid (int))
    abort();

  auto *p = &i;
  if (typeid (p) != typeid (int*))
    abort();

  auto *p2 = &p;
  if (typeid (p2) != typeid (int**))
    abort();

  auto (*fp)() = f;
  if (typeid (fp) != typeid (int (*)()))
    abort();

  auto A::* pm = &A::i;
  if (typeid (pm) != typeid (int A::*))
    abort();

  auto (A::*pmf)() = &A::f;
  if (typeid (pmf) != typeid (int (A::*)()))
    abort();

  g(42);
  g(10.f);
  g(A());

  auto *p3 = new auto (i);
  if (typeid (p3) != typeid (int*))
    abort();

  for (auto idx = i; idx != 0; idx = 0);
  while (auto idx = 0);
  if (auto idx = 1);

  switch (auto s = i)
    {
    case 42:
      break;
    }

  auto j = 42, k = 24;
}