summaryrefslogtreecommitdiffstats
path: root/test/SemaTemplate/member-access-expr.cpp
blob: 116e8377b366ea5aa7d12369214ecd7058d2044d (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<typename T>
void call_f0(T x) {
  x.Base::f0();
}

struct Base {
  void f0();
};

struct X0 : Base { 
  typedef Base CrazyBase;
};

void test_f0(X0 x0) {
  call_f0(x0);
}

template<typename TheBase, typename T>
void call_f0_through_typedef(T x) {
  typedef TheBase Base2;
  x.Base2::f0();
}

void test_f0_through_typedef(X0 x0) {
  call_f0_through_typedef<Base>(x0);
}

template<typename TheBase, typename T>
void call_f0_through_typedef2(T x) {
  typedef TheBase CrazyBase; // expected-note{{current scope}}
  x.CrazyBase::f0(); // expected-error{{ambiguous}} \
                     // expected-error 2{{no member named}}
}

struct OtherBase { };

struct X1 : Base, OtherBase { 
  typedef OtherBase CrazyBase; // expected-note{{object type}}
};

void test_f0_through_typedef2(X0 x0, X1 x1) {
  call_f0_through_typedef2<Base>(x0);
  call_f0_through_typedef2<OtherBase>(x1); // expected-note{{instantiation}}
  call_f0_through_typedef2<Base>(x1); // expected-note{{instantiation}}
}


struct X2 {
  operator int() const;
};

template<typename T, typename U>
T convert(const U& value) {
  return value.operator T(); // expected-error{{operator long}}
}

void test_convert(X2 x2) {
  convert<int>(x2);
  convert<long>(x2); // expected-note{{instantiation}}
}

template<typename T>
void destruct(T* ptr) {
  ptr->~T();
}

template<typename T>
void destruct_intptr(int *ip) {
  ip->~T();
}

void test_destruct(X2 *x2p, int *ip) {
  destruct(x2p);
  destruct(ip);
  destruct_intptr<int>(ip);
}

// PR5220
class X3 {
protected:
  template <int> float* &f0();
  template <int> const float* &f0() const;
  void f1() {
    (void)static_cast<float*>(f0<0>());
  }
  void f1() const{
    (void)f0<0>();
  }
};

// Fun with template instantiation and conversions
struct X4 {
  int& member();
  float& member() const;
};

template<typename T>
struct X5 {
  void f(T* ptr) { int& ir = ptr->member(); }
  void g(T* ptr) { float& fr = ptr->member(); }
};

void test_X5(X5<X4> x5, X5<const X4> x5c, X4 *xp, const X4 *cxp) {
  x5.f(xp);
  x5c.g(cxp);
}

// In theory we can do overload resolution at template-definition time on this.
// We should at least not assert.
namespace test4 {
  struct Base {
    template <class T> void foo() {}
  };

  template <class T> struct Foo : Base {
    void test() {
      foo<int>();
    }
  };
}
OpenPOWER on IntegriCloud