xref: /minix3/external/bsd/llvm/dist/clang/test/SemaTemplate/instantiate-member-expr.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic
2*f4a2713aSLionel Sambuc template<typename T>
3*f4a2713aSLionel Sambuc struct S {
SS4*f4a2713aSLionel Sambuc  S() { }
5*f4a2713aSLionel Sambuc };
6*f4a2713aSLionel Sambuc 
7*f4a2713aSLionel Sambuc template<typename T>
8*f4a2713aSLionel Sambuc struct vector {
push_backvector9*f4a2713aSLionel Sambuc   void push_back(const T&) { int a[sizeof(T) ? -1: -1]; } // expected-error {{array with a negative size}}
10*f4a2713aSLionel Sambuc };
11*f4a2713aSLionel Sambuc 
12*f4a2713aSLionel Sambuc class ExprEngine {
13*f4a2713aSLionel Sambuc public:
14*f4a2713aSLionel Sambuc  typedef vector<S<void *> >CheckersOrdered;
15*f4a2713aSLionel Sambuc  CheckersOrdered Checkers;
16*f4a2713aSLionel Sambuc 
17*f4a2713aSLionel Sambuc  template <typename CHECKER>
registerCheck(CHECKER * check)18*f4a2713aSLionel Sambuc  void registerCheck(CHECKER *check) {
19*f4a2713aSLionel Sambuc    Checkers.push_back(S<void *>()); // expected-note {{in instantiation of member function 'vector<S<void *> >::push_back' requested here}}
20*f4a2713aSLionel Sambuc  }
21*f4a2713aSLionel Sambuc };
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc class RetainReleaseChecker { };
24*f4a2713aSLionel Sambuc 
f(ExprEngine & Eng)25*f4a2713aSLionel Sambuc void f(ExprEngine& Eng) {
26*f4a2713aSLionel Sambuc    Eng.registerCheck(new RetainReleaseChecker); // expected-note {{in instantiation of function template specialization 'ExprEngine::registerCheck<RetainReleaseChecker>' requested here}}
27*f4a2713aSLionel Sambuc }
28*f4a2713aSLionel Sambuc 
29*f4a2713aSLionel Sambuc // PR 5838
30*f4a2713aSLionel Sambuc namespace test1 {
31*f4a2713aSLionel Sambuc   template<typename T> struct A {
32*f4a2713aSLionel Sambuc     int a;
33*f4a2713aSLionel Sambuc   };
34*f4a2713aSLionel Sambuc 
35*f4a2713aSLionel Sambuc   template<typename T> struct B : A<float>, A<T> {
ftest1::B36*f4a2713aSLionel Sambuc     void f() {
37*f4a2713aSLionel Sambuc       a = 0; // should not be ambiguous
38*f4a2713aSLionel Sambuc     }
39*f4a2713aSLionel Sambuc   };
40*f4a2713aSLionel Sambuc   template struct B<int>;
41*f4a2713aSLionel Sambuc 
42*f4a2713aSLionel Sambuc   struct O {
43*f4a2713aSLionel Sambuc     int a;
44*f4a2713aSLionel Sambuc     template<typename T> struct B : A<T> {
ftest1::O::B45*f4a2713aSLionel Sambuc       void f() {
46*f4a2713aSLionel Sambuc         a = 0; // expected-error {{'test1::O::a' is not a member of class 'test1::O::B<int>'}}
47*f4a2713aSLionel Sambuc       }
48*f4a2713aSLionel Sambuc     };
49*f4a2713aSLionel Sambuc   };
50*f4a2713aSLionel Sambuc   template struct O::B<int>; // expected-note {{in instantiation}}
51*f4a2713aSLionel Sambuc }
52*f4a2713aSLionel Sambuc 
53*f4a2713aSLionel Sambuc // PR7248
54*f4a2713aSLionel Sambuc namespace test2 {
55*f4a2713aSLionel Sambuc   template <class T> struct A {
footest2::A56*f4a2713aSLionel Sambuc     void foo() {
57*f4a2713aSLionel Sambuc       T::bar(); // expected-error {{type 'int' cannot}}
58*f4a2713aSLionel Sambuc     }
59*f4a2713aSLionel Sambuc   };
60*f4a2713aSLionel Sambuc 
61*f4a2713aSLionel Sambuc   template <class T> class B {
foo(A<T> a)62*f4a2713aSLionel Sambuc     void foo(A<T> a) {
63*f4a2713aSLionel Sambuc       a.test2::template A<T>::foo(); // expected-note {{in instantiation}}
64*f4a2713aSLionel Sambuc     }
65*f4a2713aSLionel Sambuc   };
66*f4a2713aSLionel Sambuc 
67*f4a2713aSLionel Sambuc   template class B<int>;
68*f4a2713aSLionel Sambuc }
69*f4a2713aSLionel Sambuc 
70*f4a2713aSLionel Sambuc namespace PR14124 {
71*f4a2713aSLionel Sambuc   template<typename T> struct S {
72*f4a2713aSLionel Sambuc     int value;
73*f4a2713aSLionel Sambuc   };
f()74*f4a2713aSLionel Sambuc   template<typename T> void f() { S<T>::value; } // expected-error {{invalid use of non-static data member 'value'}}
75*f4a2713aSLionel Sambuc   template void f<int>(); // expected-note {{in instantiation of}}
76*f4a2713aSLionel Sambuc 
77*f4a2713aSLionel Sambuc   struct List { List *next; };
78*f4a2713aSLionel Sambuc   template<typename T, T *(T::*p) = &T::next> struct A {};
79*f4a2713aSLionel Sambuc   A<List> a; // ok
80*f4a2713aSLionel Sambuc   void operator&(struct Whatever);
81*f4a2713aSLionel Sambuc   template<typename T, T *(T::*p) = &T::next> struct B {};
82*f4a2713aSLionel Sambuc   B<List> b; // still ok
83*f4a2713aSLionel Sambuc }
84