aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/cpp0x/decltype4.C
blob: c14e156465d1d57fd5384a60f105334550a6499b (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
75
76
77
78
79
80
81
82
// { dg-do compile { target c++11 } }

template<typename T, typename U> 
struct is_same 
{
  static const bool value = false;
};

template<typename T>
struct is_same<T, T>
{
  static const bool value = true;
};

#define CHECK_DECLTYPE(DECLTYPE,RESULT) \
  static_assert(is_same< DECLTYPE , RESULT >::value, #DECLTYPE " should be " #RESULT)

struct A {
  int x; 
  int& y; 
  int foo(char); 
  int& bar() const; 
}; 

CHECK_DECLTYPE(decltype(&A::x), int A::*);
decltype(&A::y) Ay; // { dg-error "cannot create pointer to reference member|invalid type" }
CHECK_DECLTYPE(decltype(&A::foo), int (A::*) (char));
CHECK_DECLTYPE(decltype(&A::bar), int& (A::*) () const);

CHECK_DECLTYPE(decltype("decltype"), const char(&)[9]);
CHECK_DECLTYPE(decltype(1), int);

int an_int = 5;
int& i = an_int; 
const int j = an_int; 

CHECK_DECLTYPE(decltype(i)&, int&);
CHECK_DECLTYPE(const decltype(j), const int);

int foo(); 
CHECK_DECLTYPE(decltype(foo()), int);
float& bar(int); 
CHECK_DECLTYPE(decltype (bar(1)), float&);
const A bar(); 
CHECK_DECLTYPE(decltype (bar()), const A);
const A& bar2(); 
CHECK_DECLTYPE(decltype (bar2()), const A&);

void wibble() {
  CHECK_DECLTYPE(decltype(1+2), int);
  int* p; 
  CHECK_DECLTYPE(decltype(*p), int&);
  int a[10]; 
  CHECK_DECLTYPE(decltype(a[3]), int&);
  int i; int& j = i; 
  CHECK_DECLTYPE(decltype (i = 5), int&);
  CHECK_DECLTYPE(decltype (j = 5), int&);

  CHECK_DECLTYPE(decltype (++i), int&); 
  CHECK_DECLTYPE(decltype (i++), int);
}

struct B {
  B () : bit(), cbit() {} 
  int bit : 2;
  const int cbit : 3;

  void foo()
  {
    CHECK_DECLTYPE(decltype(bit), int);
    CHECK_DECLTYPE(decltype((bit)), int&);
    CHECK_DECLTYPE(decltype(cbit), const int);
    CHECK_DECLTYPE(decltype((cbit)), const int&);
  }
};

B b;
const B& bc = b;
CHECK_DECLTYPE(decltype(b.bit), int);
CHECK_DECLTYPE(decltype(bc.bit), int);
CHECK_DECLTYPE(decltype((b.bit)), int&);
CHECK_DECLTYPE(decltype((bc.bit)), const int&);