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