Daniel Dunbar | 8fbe78f | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Charles Li | 85dec55 | 2015-12-10 01:07:17 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s |
| 3 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 4 | |
| 5 | namespace N { |
| 6 | namespace M { |
Chris Lattner | b4a8fe8 | 2009-04-14 22:17:06 +0000 | [diff] [blame] | 7 | template<typename T> struct Promote; |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 8 | |
| 9 | template<> struct Promote<short> { |
| 10 | typedef int type; |
| 11 | }; |
| 12 | |
| 13 | template<> struct Promote<int> { |
| 14 | typedef int type; |
| 15 | }; |
| 16 | |
| 17 | template<> struct Promote<float> { |
| 18 | typedef double type; |
| 19 | }; |
| 20 | |
| 21 | Promote<short>::type *ret_intptr(int* ip) { return ip; } |
| 22 | Promote<int>::type *ret_intptr2(int* ip) { return ip; } |
| 23 | } |
| 24 | |
| 25 | M::Promote<int>::type *ret_intptr3(int* ip) { return ip; } |
Charles Li | 85dec55 | 2015-12-10 01:07:17 +0000 | [diff] [blame] | 26 | M::template Promote<int>::type *ret_intptr4(int* ip) { return ip; } |
| 27 | #if __cplusplus <= 199711L |
| 28 | // expected-warning@-2 {{'template' keyword outside of a template}} |
| 29 | #endif |
| 30 | |
| 31 | M::template Promote<int> pi; |
| 32 | #if __cplusplus <= 199711L |
| 33 | // expected-warning@-2 {{'template' keyword outside of a template}} |
| 34 | #endif |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | N::M::Promote<int>::type *ret_intptr5(int* ip) { return ip; } |
| 38 | ::N::M::Promote<int>::type *ret_intptr6(int* ip) { return ip; } |
| 39 | |
| 40 | |
Douglas Gregor | 120635b | 2009-11-11 16:39:34 +0000 | [diff] [blame] | 41 | N::M::template; // expected-error{{expected unqualified-id}} |
| 42 | N::M::template Promote; // expected-error{{expected unqualified-id}} |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 43 | |
| 44 | namespace N { |
| 45 | template<typename T> struct A; |
| 46 | |
| 47 | template<> |
| 48 | struct A<int> { |
| 49 | struct X; |
| 50 | }; |
Douglas Gregor | b67535d | 2009-03-31 00:43:58 +0000 | [diff] [blame] | 51 | |
| 52 | struct B; |
Douglas Gregor | 7f74112 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | struct ::N::A<int>::X { |
| 56 | int foo; |
| 57 | }; |
Douglas Gregor | b67535d | 2009-03-31 00:43:58 +0000 | [diff] [blame] | 58 | |
Douglas Gregor | b67535d | 2009-03-31 00:43:58 +0000 | [diff] [blame] | 59 | template<typename T> |
| 60 | struct TestA { |
Douglas Gregor | 120635b | 2009-11-11 16:39:34 +0000 | [diff] [blame] | 61 | typedef typename N::template B<T>::type type; // expected-error{{'B' following the 'template' keyword does not refer to a template}} \ |
Douglas Gregor | 120635b | 2009-11-11 16:39:34 +0000 | [diff] [blame] | 62 | // expected-error{{expected member name}} |
Douglas Gregor | b67535d | 2009-03-31 00:43:58 +0000 | [diff] [blame] | 63 | }; |
John McCall | 99b2fe5 | 2010-04-29 23:50:39 +0000 | [diff] [blame] | 64 | |
| 65 | // Reduced from a Boost failure. |
| 66 | namespace test1 { |
| 67 | template <class T> struct pair { |
| 68 | T x; |
| 69 | T y; |
| 70 | |
| 71 | static T pair<T>::* const mem_array[2]; |
| 72 | }; |
| 73 | |
| 74 | template <class T> |
| 75 | T pair<T>::* const pair<T>::mem_array[2] = { &pair<T>::x, &pair<T>::y }; |
| 76 | } |
Douglas Gregor | f3d3ae6 | 2010-05-14 04:53:42 +0000 | [diff] [blame] | 77 | |
| 78 | typedef int T; |
| 79 | namespace N1 { |
| 80 | template<typename T> T f0(); |
| 81 | } |
| 82 | |
| 83 | template<typename T> T N1::f0() { } |
Douglas Gregor | ffa2039 | 2010-06-17 16:03:49 +0000 | [diff] [blame] | 84 | |
| 85 | namespace PR7385 { |
| 86 | template< typename > struct has_xxx0 |
| 87 | { |
| 88 | template< typename > struct has_xxx0_introspect |
| 89 | { |
| 90 | template< typename > struct has_xxx0_substitute ; |
| 91 | template< typename V > |
| 92 | int int00( has_xxx0_substitute < typename V::template xxx< > > = 0 ); |
| 93 | }; |
| 94 | static const int value = has_xxx0_introspect<int>::value; // expected-error{{no member named 'value'}} |
| 95 | typedef int type; |
| 96 | }; |
| 97 | |
| 98 | has_xxx0<int>::type t; // expected-note{{instantiation of}} |
| 99 | } |
Douglas Gregor | df65c8ed | 2010-07-28 14:49:07 +0000 | [diff] [blame] | 100 | |
| 101 | namespace PR7725 { |
| 102 | template<class ignored> struct TypedefProvider; |
| 103 | template<typename T> |
| 104 | struct TemplateClass : public TypedefProvider<T> |
| 105 | { |
| 106 | void PrintSelf() { |
| 107 | TemplateClass::Test::PrintSelf(); |
| 108 | } |
| 109 | }; |
| 110 | } |
Douglas Gregor | 8b6070b | 2011-03-04 21:37:14 +0000 | [diff] [blame] | 111 | |
| 112 | namespace PR9226 { |
| 113 | template<typename a> |
| 114 | void nt() // expected-note{{function template 'nt' declared here}} |
| 115 | { nt<>:: } // expected-error{{qualified name refers into a specialization of function template 'nt'}} \ |
| 116 | // expected-error{{expected unqualified-id}} |
| 117 | |
| 118 | template<typename T> |
| 119 | void f(T*); // expected-note{{function template 'f' declared here}} |
| 120 | |
| 121 | template<typename T> |
| 122 | void f(T*, T*); // expected-note{{function template 'f' declared here}} |
| 123 | |
| 124 | void g() { |
| 125 | f<int>:: // expected-error{{qualified name refers into a specialization of function template 'f'}} |
| 126 | } // expected-error{{expected unqualified-id}} |
| 127 | |
| 128 | struct X { |
| 129 | template<typename T> void f(); // expected-note{{function template 'f' declared here}} |
| 130 | }; |
| 131 | |
| 132 | template<typename T, typename U> |
| 133 | struct Y { |
| 134 | typedef typename T::template f<U> type; // expected-error{{template name refers to non-type template 'X::f'}} |
| 135 | }; |
| 136 | |
| 137 | Y<X, int> yxi; // expected-note{{in instantiation of template class 'PR9226::Y<PR9226::X, int>' requested here}} |
| 138 | } |
Douglas Gregor | 5ecbb1b | 2011-03-11 23:27:41 +0000 | [diff] [blame] | 139 | |
| 140 | namespace PR9449 { |
| 141 | template <typename T> |
| 142 | struct s; // expected-note{{template is declared here}} |
| 143 | |
| 144 | template <typename T> |
| 145 | void f() { |
| 146 | int s<T>::template n<T>::* f; // expected-error{{implicit instantiation of undefined template 'PR9449::s<int>'}} \ |
| 147 | // expected-error{{following the 'template' keyword}} |
| 148 | } |
| 149 | |
| 150 | template void f<int>(); // expected-note{{in instantiation of}} |
| 151 | } |