Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | 551f48c | 2009-03-27 04:21:56 +0000 | [diff] [blame] | 2 | class A; |
| 3 | |
| 4 | class S { |
| 5 | public: |
| 6 | template<typename T> struct A { |
| 7 | struct Nested { |
| 8 | typedef T type; |
| 9 | }; |
| 10 | }; |
| 11 | }; |
| 12 | |
| 13 | int i; |
| 14 | S::A<int>::Nested::type *ip = &i; |
| 15 | |
Douglas Gregor | c305833 | 2009-08-24 23:03:25 +0000 | [diff] [blame] | 16 | template<typename T> |
Douglas Gregor | 05396e2 | 2009-08-25 17:23:04 +0000 | [diff] [blame] | 17 | struct Outer { |
| 18 | template<typename U> |
| 19 | class Inner0; |
Douglas Gregor | c305833 | 2009-08-24 23:03:25 +0000 | [diff] [blame] | 20 | |
| 21 | template<typename U> |
Douglas Gregor | 05396e2 | 2009-08-25 17:23:04 +0000 | [diff] [blame] | 22 | class Inner1 { |
| 23 | struct ReallyInner; |
| 24 | |
| 25 | T foo(U); |
| 26 | template<typename V> T bar(V); |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 27 | template<typename V> T* bar(V); |
Douglas Gregor | c131ebb | 2009-08-25 22:53:07 +0000 | [diff] [blame] | 28 | |
| 29 | static T value1; |
| 30 | static U value2; |
Douglas Gregor | c305833 | 2009-08-24 23:03:25 +0000 | [diff] [blame] | 31 | }; |
| 32 | }; |
| 33 | |
Douglas Gregor | 05396e2 | 2009-08-25 17:23:04 +0000 | [diff] [blame] | 34 | template<typename X> |
| 35 | template<typename Y> |
| 36 | class Outer<X>::Inner0 { |
| 37 | public: |
| 38 | void f(X, Y); |
| 39 | }; |
Douglas Gregor | c305833 | 2009-08-24 23:03:25 +0000 | [diff] [blame] | 40 | |
Douglas Gregor | 05396e2 | 2009-08-25 17:23:04 +0000 | [diff] [blame] | 41 | template<typename X> |
| 42 | template<typename Y> |
| 43 | void Outer<X>::Inner0<Y>::f(X, Y) { |
| 44 | } |
| 45 | |
| 46 | template<typename X> |
| 47 | template<typename Y> |
| 48 | struct Outer<X>::Inner1<Y>::ReallyInner { |
Douglas Gregor | bc047ba | 2009-08-25 22:54:02 +0000 | [diff] [blame] | 49 | static Y value3; |
| 50 | |
Douglas Gregor | 05396e2 | 2009-08-25 17:23:04 +0000 | [diff] [blame] | 51 | void g(X, Y); |
| 52 | }; |
| 53 | |
| 54 | template<typename X> |
| 55 | template<typename Y> |
| 56 | void Outer<X>::Inner1<Y>::ReallyInner::g(X, Y) { |
| 57 | } |
| 58 | |
| 59 | template<typename X> |
| 60 | template<typename Y> |
| 61 | X Outer<X>::Inner1<Y>::foo(Y) { |
| 62 | return X(); |
| 63 | } |
| 64 | |
| 65 | template<typename X> |
| 66 | template<typename Y> |
| 67 | template<typename Z> |
| 68 | X Outer<X>::Inner1<Y>::bar(Z) { |
| 69 | return X(); |
| 70 | } |
Douglas Gregor | 495c35d | 2009-08-25 22:51:20 +0000 | [diff] [blame] | 71 | |
| 72 | template<typename X> |
| 73 | template<typename Y> |
| 74 | template<typename Z> |
| 75 | X* Outer<X>::Inner1<Y>::bar(Z) { |
| 76 | return 0; |
| 77 | } |
Douglas Gregor | c131ebb | 2009-08-25 22:53:07 +0000 | [diff] [blame] | 78 | |
| 79 | template<typename X> |
| 80 | template<typename Y> |
| 81 | X Outer<X>::Inner1<Y>::value1 = 0; |
| 82 | |
| 83 | template<typename X> |
| 84 | template<typename Y> |
| 85 | Y Outer<X>::Inner1<Y>::value2 = Y(); |
Douglas Gregor | bc047ba | 2009-08-25 22:54:02 +0000 | [diff] [blame] | 86 | |
| 87 | template<typename X> |
| 88 | template<typename Y> |
| 89 | Y Outer<X>::Inner1<Y>::ReallyInner::value3 = Y(); |
Douglas Gregor | dacd434 | 2009-08-26 00:04:55 +0000 | [diff] [blame] | 90 | |
| 91 | template<typename X> |
| 92 | template<typename Y> |
| 93 | Y Outer<X>::Inner1<Y*>::ReallyInner::value4; // expected-error{{Outer<X>::Inner1<Y *>::ReallyInner::}} |
Douglas Gregor | 1cdcc57 | 2009-09-10 00:12:48 +0000 | [diff] [blame] | 94 | |
| 95 | |
| 96 | template<typename T> |
| 97 | struct X0 { }; |
| 98 | |
| 99 | template<typename T> |
| 100 | struct X0<T*> { |
| 101 | template<typename U> |
| 102 | void f(U u = T()) { } |
| 103 | }; |
Douglas Gregor | 33642df | 2009-10-23 23:25:44 +0000 | [diff] [blame] | 104 | |
| 105 | // PR5103 |
| 106 | template<typename> |
| 107 | struct X1 { |
| 108 | template<typename, bool = false> struct B { }; |
| 109 | }; |
| 110 | template struct X1<int>::B<bool>; |
Douglas Gregor | 9106ef7 | 2009-11-11 16:58:32 +0000 | [diff] [blame] | 111 | |
| 112 | // Template template parameters |
| 113 | template<typename T> |
| 114 | struct X2 { |
| 115 | template<template<class U, T Value> class> // expected-error{{cannot have type 'float'}} \ |
| 116 | // expected-note{{previous non-type template}} |
| 117 | struct Inner { }; |
| 118 | }; |
| 119 | |
| 120 | template<typename T, |
| 121 | int Value> // expected-note{{template non-type parameter}} |
| 122 | struct X2_arg; |
| 123 | |
| 124 | X2<int>::Inner<X2_arg> x2i1; |
Douglas Gregor | 9148c3f | 2009-11-11 19:13:48 +0000 | [diff] [blame] | 125 | X2<float> x2a; // expected-note{{instantiation}} |
Douglas Gregor | 9106ef7 | 2009-11-11 16:58:32 +0000 | [diff] [blame] | 126 | X2<long>::Inner<X2_arg> x2i3; // expected-error{{template template argument has different}} |
| 127 | |
Douglas Gregor | f250365 | 2011-09-21 14:40:46 +0000 | [diff] [blame] | 128 | namespace PR10896 { |
| 129 | template<typename TN> |
| 130 | class Foo { |
Douglas Gregor | 9106ef7 | 2009-11-11 16:58:32 +0000 | [diff] [blame] | 131 | |
Douglas Gregor | f250365 | 2011-09-21 14:40:46 +0000 | [diff] [blame] | 132 | public: |
| 133 | void foo() {} |
| 134 | private: |
| 135 | |
| 136 | template<typename T> |
| 137 | T SomeField; // expected-error {{member 'SomeField' declared as a template}} |
| 138 | }; |
| 139 | |
| 140 | void g() { |
| 141 | Foo<int> f; |
| 142 | f.foo(); |
| 143 | } |
| 144 | } |
Douglas Gregor | ea9f54a | 2011-11-01 21:35:16 +0000 | [diff] [blame] | 145 | |
| 146 | namespace PR10924 { |
| 147 | template< class Topology, class ctype > |
| 148 | struct ReferenceElement |
| 149 | { |
| 150 | }; |
| 151 | |
| 152 | template< class Topology, class ctype > |
| 153 | template< int codim > |
| 154 | class ReferenceElement< Topology, ctype > :: BaryCenterArray // expected-error{{out-of-line definition of 'BaryCenterArray' does not match any declaration in 'ReferenceElement<Topology, ctype>'}} |
| 155 | { |
| 156 | }; |
| 157 | } |