blob: 733dc7fa184ed80b9c33412c2925e4b50257eb9c [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregord57959a2009-03-27 23:10:48 +00002namespace N {
3 struct A {
4 typedef int type;
5 };
6
7 struct B {
8 };
9
10 struct C {
11 struct type { };
12 int type; // expected-note 2{{referenced member 'type' is declared here}}
13 };
14}
15
16int i;
17
Douglas Gregor1a15dae2010-06-16 22:31:08 +000018typename N::A::type *ip1 = &i; // expected-warning{{'typename' occurs outside of a template}}
19typename N::B::type *ip2 = &i; // expected-error{{no type named 'type' in 'N::B'}} \
20// expected-warning{{'typename' occurs outside of a template}}
21typename N::C::type *ip3 = &i; // expected-error{{typename specifier refers to non-type member 'type'}} \
22// expected-warning{{'typename' occurs outside of a template}}
Douglas Gregord57959a2009-03-27 23:10:48 +000023
24void test(double d) {
Richard Smithb9c62612012-07-30 21:30:52 +000025 typename N::A::type f(typename N::A::type(a)); // expected-warning{{disambiguated as a function declaration}} \
26 // expected-note{{add a pair of parentheses}} expected-warning 2{{'typename' occurs outside of a template}}
Douglas Gregord57959a2009-03-27 23:10:48 +000027 int five = f(5);
28
29 using namespace N;
Douglas Gregor1a15dae2010-06-16 22:31:08 +000030 for (typename A::type i = 0; i < 10; ++i) // expected-warning{{'typename' occurs outside of a template}}
Douglas Gregord57959a2009-03-27 23:10:48 +000031 five += 1;
32
Douglas Gregor1a15dae2010-06-16 22:31:08 +000033 const typename N::A::type f2(d); // expected-warning{{'typename' occurs outside of a template}}
Douglas Gregord57959a2009-03-27 23:10:48 +000034}
35
36namespace N {
37 template<typename T>
38 struct X {
John McCall7c2342d2010-03-10 11:27:22 +000039 typedef typename T::type type; // expected-error {{no type named 'type' in 'N::B'}} \
40 // expected-error {{no type named 'type' in 'B'}} \
Douglas Gregord57959a2009-03-27 23:10:48 +000041 // FIXME: location info for error above isn't very good \
42 // expected-error 2{{typename specifier refers to non-type member 'type'}} \
43 // expected-error{{type 'int' cannot be used prior to '::' because it has no members}}
44 };
45}
46
47N::X<N::A>::type *ip4 = &i;
Jeffrey Yasskin9ab14542010-04-08 16:38:48 +000048N::X<N::B>::type *ip5 = &i; // expected-note{{in instantiation of template class 'N::X<N::B>' requested here}}
49N::X<N::C>::type *ip6 = &i; // expected-note{{in instantiation of template class 'N::X<N::C>' requested here}}
Douglas Gregord57959a2009-03-27 23:10:48 +000050
Jeffrey Yasskin9ab14542010-04-08 16:38:48 +000051N::X<int>::type fail1; // expected-note{{in instantiation of template class 'N::X<int>' requested here}}
Douglas Gregord57959a2009-03-27 23:10:48 +000052
53template<typename T>
54struct Y {
John McCall7c2342d2010-03-10 11:27:22 +000055 typedef typename N::X<T>::type *type; // expected-note{{in instantiation of template class 'N::X<B>' requested here}} \
56 // expected-note{{in instantiation of template class 'N::X<C>' requested here}}
Douglas Gregord57959a2009-03-27 23:10:48 +000057};
58
59struct A {
60 typedef int type;
61};
62
63struct B {
64};
65
66struct C {
67 struct type { };
68 int type; // expected-note{{referenced member 'type' is declared here}}
69};
70
71::Y<A>::type ip7 = &i;
Jeffrey Yasskin9ab14542010-04-08 16:38:48 +000072::Y<B>::type ip8 = &i; // expected-note{{in instantiation of template class 'Y<B>' requested here}}
73::Y<C>::type ip9 = &i; // expected-note{{in instantiation of template class 'Y<C>' requested here}}
Richard Trieu00c93a12011-05-07 01:36:37 +000074
75template<typename T> struct D {
76 typedef typename T::foo foo; // expected-error {{type 'long' cannot be used prior to '::' because it has no members}}
77 typedef typename foo::bar bar;
78};
79
80D<long> struct_D; // expected-note {{in instantiation of template class 'D<long>' requested here}}
81
82template<typename T> struct E {
83 typedef typename T::foo foo;
84 typedef typename foo::bar bar; // expected-error {{type 'foo' (aka 'double') cannot be used prior to '::' because it has no members}}
85};
86
87struct F {
88 typedef double foo;
89};
90
91E<F> struct_E; // expected-note {{in instantiation of template class 'E<F>' requested here}}
92
93template<typename T> struct G {
94 typedef typename T::foo foo;
95 typedef typename foo::bar bar;
96};
97
98struct H {
99 struct foo {
100 typedef double bar;
101 };
102};
103
104G<H> struct_G;
Douglas Gregor480b53c2011-09-26 14:30:28 +0000105
106namespace PR10925 {
107 template< int mydim, typename Traits >
108 class BasicGeometry
109 {
110 typedef int some_type_t;
111 };
112
113 template<class ctype, int mydim, int coorddim>
114 class MockGeometry : BasicGeometry<mydim, int>{
115 using typename BasicGeometry<mydim, int>::operator[]; // expected-error {{typename is allowed for identifiers only}}
116 };
117}
Kaelyn Uhrainab7ad722012-05-18 23:42:49 +0000118
119
120namespace missing_typename {
Kaelyn Uhrain8c14de82012-06-08 01:07:26 +0000121template <class T1, class T2> struct pair {}; // expected-note 7 {{template parameter is declared here}}
Kaelyn Uhrainab7ad722012-05-18 23:42:49 +0000122
123template <class T1, class T2>
124struct map {
125 typedef T1* iterator;
126};
127
128template <class T>
129class ExampleClass1 {
130 struct ExampleItem;
131
132
133 struct ExampleItemSet {
134 typedef ExampleItem* iterator;
Kaelyn Uhrain8c14de82012-06-08 01:07:26 +0000135 ExampleItem* operator[](unsigned);
Kaelyn Uhrainab7ad722012-05-18 23:42:49 +0000136 };
137
138 void foo() {
139 pair<ExampleItemSet::iterator, int> i; // expected-error {{template argument for template type parameter must be a type; did you forget 'typename'?}}
Kaelyn Uhrain8c14de82012-06-08 01:07:26 +0000140 pair<this->ExampleItemSet::iterator, int> i; // expected-error-re {{template argument for template type parameter must be a type$}}
141 pair<ExampleItemSet::operator[], int> i; // expected-error-re {{template argument for template type parameter must be a type$}}
Kaelyn Uhrainab7ad722012-05-18 23:42:49 +0000142 }
143 pair<ExampleItemSet::iterator, int> elt; // expected-error {{template argument for template type parameter must be a type; did you forget 'typename'?}}
144
145
146 typedef map<int, ExampleItem*> ExampleItemMap;
147
148 static void bar() {
149 pair<ExampleItemMap::iterator, int> i; // expected-error {{template argument for template type parameter must be a type; did you forget 'typename'?}}
150 }
151 pair<ExampleItemMap::iterator, int> entry; // expected-error {{template argument for template type parameter must be a type; did you forget 'typename'?}}
152 pair<bar, int> foobar; // expected-error {{template argument for template type parameter must be a type}}
153};
154} // namespace missing_typename