blob: 9c72845fb6a64aabb99a45ba7d9908321d6723e0 [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregor7f741122009-02-25 19:37:18 +00002
3namespace N {
4 namespace M {
Chris Lattnerb4a8fe82009-04-14 22:17:06 +00005 template<typename T> struct Promote;
Douglas Gregor7f741122009-02-25 19:37:18 +00006
7 template<> struct Promote<short> {
8 typedef int type;
9 };
10
11 template<> struct Promote<int> {
12 typedef int type;
13 };
14
15 template<> struct Promote<float> {
16 typedef double type;
17 };
18
19 Promote<short>::type *ret_intptr(int* ip) { return ip; }
20 Promote<int>::type *ret_intptr2(int* ip) { return ip; }
21 }
22
23 M::Promote<int>::type *ret_intptr3(int* ip) { return ip; }
Douglas Gregorf7d77712010-06-16 22:31:08 +000024 M::template Promote<int>::type *ret_intptr4(int* ip) { return ip; } // expected-warning{{'template' keyword outside of a template}}
Douglas Gregorbb119652010-06-16 23:00:59 +000025 M::template Promote<int> pi; // expected-warning{{'template' keyword outside of a template}}
Douglas Gregor7f741122009-02-25 19:37:18 +000026}
27
28N::M::Promote<int>::type *ret_intptr5(int* ip) { return ip; }
29::N::M::Promote<int>::type *ret_intptr6(int* ip) { return ip; }
30
31
Douglas Gregor120635b2009-11-11 16:39:34 +000032N::M::template; // expected-error{{expected unqualified-id}}
33N::M::template Promote; // expected-error{{expected unqualified-id}}
Douglas Gregor7f741122009-02-25 19:37:18 +000034
35namespace N {
36 template<typename T> struct A;
37
38 template<>
39 struct A<int> {
40 struct X;
41 };
Douglas Gregorb67535d2009-03-31 00:43:58 +000042
43 struct B;
Douglas Gregor7f741122009-02-25 19:37:18 +000044}
45
46struct ::N::A<int>::X {
47 int foo;
48};
Douglas Gregorb67535d2009-03-31 00:43:58 +000049
Douglas Gregorb67535d2009-03-31 00:43:58 +000050template<typename T>
51struct TestA {
Douglas Gregor120635b2009-11-11 16:39:34 +000052 typedef typename N::template B<T>::type type; // expected-error{{'B' following the 'template' keyword does not refer to a template}} \
Douglas Gregor120635b2009-11-11 16:39:34 +000053 // expected-error{{expected member name}}
Douglas Gregorb67535d2009-03-31 00:43:58 +000054};
John McCall99b2fe52010-04-29 23:50:39 +000055
56// Reduced from a Boost failure.
57namespace test1 {
58 template <class T> struct pair {
59 T x;
60 T y;
61
62 static T pair<T>::* const mem_array[2];
63 };
64
65 template <class T>
66 T pair<T>::* const pair<T>::mem_array[2] = { &pair<T>::x, &pair<T>::y };
67}
Douglas Gregorf3d3ae62010-05-14 04:53:42 +000068
69typedef int T;
70namespace N1 {
71 template<typename T> T f0();
72}
73
74template<typename T> T N1::f0() { }
Douglas Gregorffa20392010-06-17 16:03:49 +000075
76namespace PR7385 {
77 template< typename > struct has_xxx0
78 {
79 template< typename > struct has_xxx0_introspect
80 {
81 template< typename > struct has_xxx0_substitute ;
82 template< typename V >
83 int int00( has_xxx0_substitute < typename V::template xxx< > > = 0 );
84 };
85 static const int value = has_xxx0_introspect<int>::value; // expected-error{{no member named 'value'}}
86 typedef int type;
87 };
88
89 has_xxx0<int>::type t; // expected-note{{instantiation of}}
90}
Douglas Gregordf65c8ed2010-07-28 14:49:07 +000091
92namespace PR7725 {
93 template<class ignored> struct TypedefProvider;
94 template<typename T>
95 struct TemplateClass : public TypedefProvider<T>
96 {
97 void PrintSelf() {
98 TemplateClass::Test::PrintSelf();
99 }
100 };
101}