xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/nested-name-spec-locations.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc // Note: the formatting in this test case is intentionally funny, with
4*f4a2713aSLionel Sambuc // nested-name-specifiers stretched out vertically so that we can
5*f4a2713aSLionel Sambuc // match up diagnostics per-line and still verify that we're getting
6*f4a2713aSLionel Sambuc // good source-location information.
7*f4a2713aSLionel Sambuc 
8*f4a2713aSLionel Sambuc namespace outer {
9*f4a2713aSLionel Sambuc   namespace inner {
10*f4a2713aSLionel Sambuc     template<typename T>
11*f4a2713aSLionel Sambuc     struct X0 {
12*f4a2713aSLionel Sambuc     };
13*f4a2713aSLionel Sambuc   }
14*f4a2713aSLionel Sambuc }
15*f4a2713aSLionel Sambuc 
16*f4a2713aSLionel Sambuc template<typename T>
17*f4a2713aSLionel Sambuc struct add_reference {
18*f4a2713aSLionel Sambuc   typedef T& type;
19*f4a2713aSLionel Sambuc };
20*f4a2713aSLionel Sambuc 
21*f4a2713aSLionel Sambuc namespace outer_alias = outer;
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc template<typename T>
24*f4a2713aSLionel Sambuc struct UnresolvedUsingValueDeclTester {
25*f4a2713aSLionel Sambuc   using outer::inner::X0<
26*f4a2713aSLionel Sambuc           typename add_reference<T>::type
27*f4a2713aSLionel Sambuc     * // expected-error{{declared as a pointer to a reference of type}}
28*f4a2713aSLionel Sambuc         >::value;
29*f4a2713aSLionel Sambuc };
30*f4a2713aSLionel Sambuc 
31*f4a2713aSLionel Sambuc UnresolvedUsingValueDeclTester<int> UnresolvedUsingValueDeclCheck; // expected-note{{in instantiation of template class}}
32*f4a2713aSLionel Sambuc 
33*f4a2713aSLionel Sambuc template<typename T>
34*f4a2713aSLionel Sambuc struct UnresolvedUsingTypenameDeclTester {
35*f4a2713aSLionel Sambuc   using outer::inner::X0<
36*f4a2713aSLionel Sambuc           typename add_reference<T>::type
37*f4a2713aSLionel Sambuc     * // expected-error{{declared as a pointer to a reference of type}}
38*f4a2713aSLionel Sambuc         >::value;
39*f4a2713aSLionel Sambuc };
40*f4a2713aSLionel Sambuc 
41*f4a2713aSLionel Sambuc UnresolvedUsingTypenameDeclTester<int> UnresolvedUsingTypenameDeclCheck; // expected-note{{in instantiation of template class}}
42*f4a2713aSLionel Sambuc 
43*f4a2713aSLionel Sambuc 
44*f4a2713aSLionel Sambuc template<typename T, typename U>
45*f4a2713aSLionel Sambuc struct PseudoDestructorExprTester {
fPseudoDestructorExprTester46*f4a2713aSLionel Sambuc   void f(T *t) {
47*f4a2713aSLionel Sambuc     t->T::template Inner<typename add_reference<U>::type
48*f4a2713aSLionel Sambuc       * // expected-error{{as a pointer to a reference of type}}
49*f4a2713aSLionel Sambuc       >::Blarg::~Blarg();
50*f4a2713aSLionel Sambuc   }
51*f4a2713aSLionel Sambuc };
52*f4a2713aSLionel Sambuc 
53*f4a2713aSLionel Sambuc struct HasInnerTemplate {
54*f4a2713aSLionel Sambuc   template<typename T>
55*f4a2713aSLionel Sambuc   struct Inner;
56*f4a2713aSLionel Sambuc 
57*f4a2713aSLionel Sambuc   typedef HasInnerTemplate T;
58*f4a2713aSLionel Sambuc };
59*f4a2713aSLionel Sambuc 
PseudoDestructorExprCheck(PseudoDestructorExprTester<HasInnerTemplate,float> tester)60*f4a2713aSLionel Sambuc void PseudoDestructorExprCheck(
61*f4a2713aSLionel Sambuc                     PseudoDestructorExprTester<HasInnerTemplate, float> tester) {
62*f4a2713aSLionel Sambuc   tester.f(0); // expected-note{{in instantiation of member function}}
63*f4a2713aSLionel Sambuc }
64*f4a2713aSLionel Sambuc 
65*f4a2713aSLionel Sambuc template<typename T>
66*f4a2713aSLionel Sambuc struct DependentScopedDeclRefExpr {
fDependentScopedDeclRefExpr67*f4a2713aSLionel Sambuc   void f() {
68*f4a2713aSLionel Sambuc     outer_alias::inner::X0<typename add_reference<T>::type
69*f4a2713aSLionel Sambuc       * // expected-error{{as a pointer to a reference of type}}
70*f4a2713aSLionel Sambuc       >::value = 17;
71*f4a2713aSLionel Sambuc   }
72*f4a2713aSLionel Sambuc };
73*f4a2713aSLionel Sambuc 
DependentScopedDeclRefExprCheck(DependentScopedDeclRefExpr<int> t)74*f4a2713aSLionel Sambuc void DependentScopedDeclRefExprCheck(DependentScopedDeclRefExpr<int> t) {
75*f4a2713aSLionel Sambuc   t.f(); // expected-note{{in instantiation of member function}}
76*f4a2713aSLionel Sambuc }
77*f4a2713aSLionel Sambuc 
78*f4a2713aSLionel Sambuc 
79*f4a2713aSLionel Sambuc template<typename T>
80*f4a2713aSLionel Sambuc struct TypenameTypeTester {
81*f4a2713aSLionel Sambuc   typedef typename outer::inner::X0<
82*f4a2713aSLionel Sambuc           typename add_reference<T>::type
83*f4a2713aSLionel Sambuc     * // expected-error{{declared as a pointer to a reference of type}}
84*f4a2713aSLionel Sambuc         >::type type;
85*f4a2713aSLionel Sambuc };
86*f4a2713aSLionel Sambuc 
87*f4a2713aSLionel Sambuc TypenameTypeTester<int> TypenameTypeCheck; // expected-note{{in instantiation of template class}}
88*f4a2713aSLionel Sambuc 
89*f4a2713aSLionel Sambuc template<typename T, typename U>
90*f4a2713aSLionel Sambuc struct DependentTemplateSpecializationTypeTester {
91*f4a2713aSLionel Sambuc   typedef typename T::template apply<typename add_reference<U>::type
92*f4a2713aSLionel Sambuc                                      * // expected-error{{declared as a pointer to a reference of type}}
93*f4a2713aSLionel Sambuc                                      >::type type;
94*f4a2713aSLionel Sambuc };
95*f4a2713aSLionel Sambuc 
96*f4a2713aSLionel Sambuc struct HasApply {
97*f4a2713aSLionel Sambuc   template<typename T>
98*f4a2713aSLionel Sambuc   struct apply {
99*f4a2713aSLionel Sambuc     typedef T type;
100*f4a2713aSLionel Sambuc   };
101*f4a2713aSLionel Sambuc };
102*f4a2713aSLionel Sambuc 
103*f4a2713aSLionel Sambuc DependentTemplateSpecializationTypeTester<HasApply, int> DTSTCheck; // expected-note{{in instantiation of template class}}
104*f4a2713aSLionel Sambuc 
105*f4a2713aSLionel Sambuc template<typename T, typename U>
106*f4a2713aSLionel Sambuc struct DependentTemplateSpecializationTypeTester2 {
107*f4a2713aSLionel Sambuc   typedef typename T::template apply<typename add_reference<U>::type
108*f4a2713aSLionel Sambuc                                      * // expected-error{{declared as a pointer to a reference of type}}
109*f4a2713aSLionel Sambuc                                      > type;
110*f4a2713aSLionel Sambuc };
111*f4a2713aSLionel Sambuc 
112*f4a2713aSLionel Sambuc DependentTemplateSpecializationTypeTester2<HasApply, int> DTSTCheck2; // expected-note{{in instantiation of template class}}
113*f4a2713aSLionel Sambuc 
114*f4a2713aSLionel Sambuc template<typename T, typename U>
115*f4a2713aSLionel Sambuc struct DependentTemplateSpecializationTypeTester3 :
116*f4a2713aSLionel Sambuc   T::template apply<typename add_reference<U>::type
117*f4a2713aSLionel Sambuc                                      * // expected-error{{declared as a pointer to a reference of type}}
118*f4a2713aSLionel Sambuc                                      >
119*f4a2713aSLionel Sambuc {};
120*f4a2713aSLionel Sambuc 
121*f4a2713aSLionel Sambuc DependentTemplateSpecializationTypeTester3<HasApply, int> DTSTCheck3; // expected-note{{in instantiation of template class}}
122*f4a2713aSLionel Sambuc 
123*f4a2713aSLionel Sambuc template<typename T, typename U>
124*f4a2713aSLionel Sambuc struct DependentTemplateSpecializationTypeTester4 {
125*f4a2713aSLionel Sambuc   typedef class T::template apply<typename add_reference<U>::type
126*f4a2713aSLionel Sambuc                                      * // expected-error{{declared as a pointer to a reference of type}}
127*f4a2713aSLionel Sambuc                                      > type;
128*f4a2713aSLionel Sambuc };
129*f4a2713aSLionel Sambuc 
130*f4a2713aSLionel Sambuc DependentTemplateSpecializationTypeTester4<HasApply, int> DTSTCheck4; // expected-note{{in instantiation of template class}}
131*f4a2713aSLionel Sambuc 
132*f4a2713aSLionel Sambuc template<template<class T> class TTP>
133*f4a2713aSLionel Sambuc struct AcceptedTemplateTemplateParameter {
134*f4a2713aSLionel Sambuc };
135*f4a2713aSLionel Sambuc 
136*f4a2713aSLionel Sambuc template<typename T, typename U>
137*f4a2713aSLionel Sambuc struct DependentTemplateTemplateArgumentTester {
138*f4a2713aSLionel Sambuc   typedef AcceptedTemplateTemplateParameter<
139*f4a2713aSLionel Sambuc             T::
140*f4a2713aSLionel Sambuc             template apply<
141*f4a2713aSLionel Sambuc               typename add_reference<U>::type
142*f4a2713aSLionel Sambuc               * // expected-error{{declared as a pointer to a reference of type}}
143*f4a2713aSLionel Sambuc             >::
144*f4a2713aSLionel Sambuc             template X>
145*f4a2713aSLionel Sambuc     type;
146*f4a2713aSLionel Sambuc };
147*f4a2713aSLionel Sambuc 
148*f4a2713aSLionel Sambuc DependentTemplateTemplateArgumentTester<HasApply, int> DTTACheck; // expected-note{{in instantiation of template class}}
149*f4a2713aSLionel Sambuc 
150*f4a2713aSLionel Sambuc namespace PR9388 {
151*f4a2713aSLionel Sambuc   namespace std {
152*f4a2713aSLionel Sambuc     template<typename T>     class vector     {
153*f4a2713aSLionel Sambuc     };
154*f4a2713aSLionel Sambuc   }
foo(std::vector<T * > & V)155*f4a2713aSLionel Sambuc   template<typename T> static void foo(std::vector<T*> &V) {
156*f4a2713aSLionel Sambuc     __PRETTY_FUNCTION__; // expected-warning{{expression result unused}}
157*f4a2713aSLionel Sambuc   }
bar(std::vector<int * > & Blocks)158*f4a2713aSLionel Sambuc   void bar(std::vector<int*> &Blocks) {
159*f4a2713aSLionel Sambuc     foo(Blocks); // expected-note{{in instantiation of}}
160*f4a2713aSLionel Sambuc   }
161*f4a2713aSLionel Sambuc 
162*f4a2713aSLionel Sambuc }
163