aboutsummaryrefslogtreecommitdiff
path: root/test/SemaTemplate
diff options
context:
space:
mode:
Diffstat (limited to 'test/SemaTemplate')
-rw-r--r--test/SemaTemplate/class-template-decl.cpp5
-rw-r--r--test/SemaTemplate/constructor-template.cpp15
-rw-r--r--test/SemaTemplate/default-expr-arguments-2.cpp19
-rw-r--r--test/SemaTemplate/default-expr-arguments.cpp30
-rw-r--r--test/SemaTemplate/dependent-names.cpp4
-rw-r--r--test/SemaTemplate/destructor-template.cpp8
-rw-r--r--test/SemaTemplate/elaborated-type-specifier.cpp36
-rw-r--r--test/SemaTemplate/explicit-specialization-member.cpp2
-rw-r--r--test/SemaTemplate/friend-template.cpp80
-rw-r--r--test/SemaTemplate/friend.cpp19
-rw-r--r--test/SemaTemplate/fun-template-def.cpp2
-rw-r--r--test/SemaTemplate/injected-class-name.cpp12
-rw-r--r--test/SemaTemplate/instantiate-complete.cpp20
-rw-r--r--test/SemaTemplate/instantiate-default-assignment-operator.cpp8
-rw-r--r--test/SemaTemplate/instantiate-expr-2.cpp19
-rw-r--r--test/SemaTemplate/instantiate-expr-5.cpp36
-rw-r--r--test/SemaTemplate/instantiate-function-1.cpp5
-rw-r--r--test/SemaTemplate/instantiate-function-params.cpp41
-rw-r--r--test/SemaTemplate/instantiate-local-class.cpp4
-rw-r--r--test/SemaTemplate/instantiate-member-class.cpp9
-rw-r--r--test/SemaTemplate/instantiate-member-expr.cpp2
-rw-r--r--test/SemaTemplate/instantiate-member-initializers.cpp5
-rw-r--r--test/SemaTemplate/instantiate-member-template.cpp2
-rw-r--r--test/SemaTemplate/instantiate-method.cpp60
-rw-r--r--test/SemaTemplate/instantiate-non-type-template-parameter.cpp24
-rw-r--r--test/SemaTemplate/instantiate-typedef.cpp3
-rw-r--r--test/SemaTemplate/instantiate-using-decl.cpp2
-rw-r--r--test/SemaTemplate/instantiation-depth.cpp10
-rw-r--r--test/SemaTemplate/nested-name-spec-template.cpp13
-rw-r--r--test/SemaTemplate/qualified-id.cpp1
-rw-r--r--test/SemaTemplate/temp_arg.cpp3
-rw-r--r--test/SemaTemplate/temp_arg_nontype.cpp39
-rw-r--r--test/SemaTemplate/temp_arg_type.cpp24
-rw-r--r--test/SemaTemplate/template-decl-fail.cpp4
-rw-r--r--test/SemaTemplate/typename-specifier-4.cpp2
-rw-r--r--test/SemaTemplate/typename-specifier.cpp15
36 files changed, 519 insertions, 64 deletions
diff --git a/test/SemaTemplate/class-template-decl.cpp b/test/SemaTemplate/class-template-decl.cpp
index 71aabe97f4e3..1be1bc070a81 100644
--- a/test/SemaTemplate/class-template-decl.cpp
+++ b/test/SemaTemplate/class-template-decl.cpp
@@ -51,3 +51,8 @@ void f() {
}
template<typename T> class X1 { } var; // expected-error{{declared as a template}}
+
+namespace M {
+}
+
+template<typename T> class M::C3 { }; // expected-error{{out-of-line definition of 'C3' does not match any declaration in namespace 'M'}}
diff --git a/test/SemaTemplate/constructor-template.cpp b/test/SemaTemplate/constructor-template.cpp
index 82c2aa4cc3e7..b6ca72e9e149 100644
--- a/test/SemaTemplate/constructor-template.cpp
+++ b/test/SemaTemplate/constructor-template.cpp
@@ -94,3 +94,18 @@ void default_ctor_inst() {
}
template void default_ctor_inst<int>();
+
+template<typename T>
+struct X5 {
+ X5();
+ X5(const T &);
+};
+
+struct X6 {
+ template<typename T> X6(T);
+};
+
+void test_X5_X6() {
+ X5<X6> tf;
+ X5<X6> tf2(tf);
+}
diff --git a/test/SemaTemplate/default-expr-arguments-2.cpp b/test/SemaTemplate/default-expr-arguments-2.cpp
new file mode 100644
index 000000000000..88cc43d6445e
--- /dev/null
+++ b/test/SemaTemplate/default-expr-arguments-2.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -ast-dump %s 2>&1 | FileCheck %s
+
+// This is a wacky test to ensure that we're actually instantiating
+// the default rguments of the constructor when the function type is
+// otherwise non-dependent.
+namespace PR6733 {
+ template <class T>
+ class bar {
+ public: enum { kSomeConst = 128 };
+ bar(int x = kSomeConst) {}
+ };
+
+ // CHECK: void f()
+ void f() {
+ // CHECK: bar<int> tmp =
+ // CHECK: CXXDefaultArgExpr{{.*}}'int'
+ bar<int> tmp;
+ }
+}
diff --git a/test/SemaTemplate/default-expr-arguments.cpp b/test/SemaTemplate/default-expr-arguments.cpp
index d2cc45b0352b..7c3525a1fb15 100644
--- a/test/SemaTemplate/default-expr-arguments.cpp
+++ b/test/SemaTemplate/default-expr-arguments.cpp
@@ -7,7 +7,8 @@ C<char>::C(int a0);
struct S { }; // expected-note 3 {{candidate constructor (the implicit copy constructor)}}
-template<typename T> void f1(T a, T b = 10) { } // expected-error{{no viable conversion}}
+template<typename T> void f1(T a, T b = 10) { } // expected-error{{no viable conversion}} \
+// expected-note{{passing argument to parameter 'b' here}}
template<typename T> void f2(T a, T b = T()) { }
@@ -25,8 +26,10 @@ void g() {
}
template<typename T> struct F {
- F(T t = 10); // expected-error{{no viable conversion}}
- void f(T t = 10); // expected-error{{no viable conversion}}
+ F(T t = 10); // expected-error{{no viable conversion}} \
+ // expected-note{{passing argument to parameter 't' here}}
+ void f(T t = 10); // expected-error{{no viable conversion}} \
+ // expected-note{{passing argument to parameter 't' here}}
};
struct FD : F<int> { };
@@ -99,7 +102,8 @@ void test_x2(X2<int> x2i, X2<NotDefaultConstructible> x2n) {
// PR5283
namespace PR5283 {
template<typename T> struct A {
- A(T = 1); // expected-error 3 {{cannot initialize a parameter of type 'int *' with an rvalue of type 'int'}}
+ A(T = 1); // expected-error 3 {{cannot initialize a parameter of type 'int *' with an rvalue of type 'int'}} \
+ // expected-note 3{{passing argument to parameter here}}
};
struct B : A<int*> {
@@ -184,3 +188,21 @@ template<> void f4<int>(int, int);
void f4_test(int i) {
f4(i);
}
+
+// Instantiate for initialization
+namespace InstForInit {
+ template<typename T>
+ struct Ptr {
+ typedef T* type;
+ Ptr(type);
+ };
+
+ template<typename T>
+ struct Holder {
+ Holder(int i, Ptr<T> ptr = 0);
+ };
+
+ void test_holder(int i) {
+ Holder<int> h(i);
+ }
+};
diff --git a/test/SemaTemplate/dependent-names.cpp b/test/SemaTemplate/dependent-names.cpp
index a2d3c56501e8..77961069c5a2 100644
--- a/test/SemaTemplate/dependent-names.cpp
+++ b/test/SemaTemplate/dependent-names.cpp
@@ -18,15 +18,18 @@ template<class T> class R : Q<T> {T current;};
namespace test0 {
template <class T> class Base {
+ public:
void instance_foo();
static void static_foo();
class Inner {
+ public:
void instance_foo();
static void static_foo();
};
};
template <class T> class Derived1 : Base<T> {
+ public:
void test0() {
Base<T>::static_foo();
Base<T>::instance_foo();
@@ -49,6 +52,7 @@ namespace test0 {
};
template <class T> class Derived2 : Base<T>::Inner {
+ public:
void test0() {
Base<T>::static_foo();
Base<T>::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
diff --git a/test/SemaTemplate/destructor-template.cpp b/test/SemaTemplate/destructor-template.cpp
index 83b1beeea997..fa1b3e0001c4 100644
--- a/test/SemaTemplate/destructor-template.cpp
+++ b/test/SemaTemplate/destructor-template.cpp
@@ -32,3 +32,11 @@ namespace PR6152 {
template struct X<int>;
}
+namespace cvquals {
+ template<typename T>
+ void f(int *ptr) {
+ ptr->~T();
+ }
+
+ template void f<const volatile int>(int *);
+}
diff --git a/test/SemaTemplate/elaborated-type-specifier.cpp b/test/SemaTemplate/elaborated-type-specifier.cpp
new file mode 100644
index 000000000000..b34660acbea0
--- /dev/null
+++ b/test/SemaTemplate/elaborated-type-specifier.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+namespace PR6915 {
+ template <typename T>
+ class D {
+ enum T::X v; // expected-error{{use of 'X' with tag type that does not match previous declaration}} \
+ // expected-error{{no enum named 'X' in 'PR6915::D3'}}
+ };
+
+ struct D1 {
+ enum X { value };
+ };
+ struct D2 {
+ class X { }; // expected-note{{previous use is here}}
+ };
+ struct D3 { };
+
+ template class D<D1>;
+ template class D<D2>; // expected-note{{in instantiation of}}
+ template class D<D3>; // expected-note{{in instantiation of}}
+}
+
+template<typename T>
+struct DeclOrDef {
+ enum T::foo; // expected-error{{nested name specifier for a declaration cannot depend on a template parameter}}
+ enum T::bar { // expected-error{{nested name specifier for a declaration cannot depend on a template parameter}}
+ value
+ };
+};
+
+namespace PR6649 {
+ template <typename T> struct foo {
+ class T::bar; // expected-error{{nested name specifier for a declaration cannot depend on a template parameter}}
+ class T::bar { int x; }; // expected-error{{nested name specifier for a declaration cannot depend on a template parameter}}
+ };
+}
diff --git a/test/SemaTemplate/explicit-specialization-member.cpp b/test/SemaTemplate/explicit-specialization-member.cpp
index cb0a39a9d0cf..417cdc1f1987 100644
--- a/test/SemaTemplate/explicit-specialization-member.cpp
+++ b/test/SemaTemplate/explicit-specialization-member.cpp
@@ -16,7 +16,7 @@ namespace PR6161 {
// expected-error{{expected class name}} \
// expected-note{{attempt to specialize declaration here}}
{
- static locale::id id; // expected-error{{use of undeclared identifier}} FIXME: expected-error {{unknown type name}}
+ static locale::id id; // expected-error{{use of undeclared identifier}}
};
numpunct<char>::~numpunct(); // expected-error{{template specialization requires 'template<>'}} \
// expected-error{{specialization of member 'PR6161::numpunct<char>::~numpunct' does not specialize an instantiated member}}
diff --git a/test/SemaTemplate/friend-template.cpp b/test/SemaTemplate/friend-template.cpp
index 6ee30aa7775a..1d62804f68ac 100644
--- a/test/SemaTemplate/friend-template.cpp
+++ b/test/SemaTemplate/friend-template.cpp
@@ -127,3 +127,83 @@ namespace PR6022 {
};
}
+namespace FriendTemplateDefinition {
+ template<unsigned > struct int_c { };
+
+ template<typename T>
+ struct X {
+ template<unsigned N>
+ friend void f(X, int_c<N>) {
+ int value = N;
+ };
+ };
+
+ void test_X(X<int> x, int_c<5> i5) {
+ f(x, i5);
+ }
+}
+
+namespace PR7013a {
+ template<class > struct X0
+ {
+ typedef int type;
+ };
+ template<typename > struct X1
+ {
+ };
+ template<typename , typename T> struct X2
+ {
+ typename T::type e;
+ };
+ namespace N
+ {
+ template <typename = int, typename = X1<int> > struct X3
+ {
+ template <typename T1, typename T2, typename B> friend void op(X2<T1, T2>& , B);
+ };
+ template <typename Ch, typename Tr, typename B> void op(X2<Ch, Tr>& , B)
+ {
+ X2<int, Tr> s;
+ }
+ }
+ int n()
+ {
+ X2<int, X0<int> > ngs;
+ N::X3<> b;
+ op(ngs, b);
+ return 0;
+ }
+}
+
+namespace PR7013b {
+ template<class > struct X0
+ {
+ typedef int type;
+ };
+ template<typename > struct X1
+ {
+ };
+ template<typename , typename T> struct X2
+ {
+ typename T::type e;
+ };
+ namespace N
+ {
+ template <typename = X1<int> > struct X3
+ {
+ template <typename T1, typename T2, typename B> friend void op(X2<T1, T2>& , B);
+ };
+ template <typename Ch, typename Tr, typename B> void op(X2<Ch, Tr>& , B)
+ {
+ X2<int, Tr> s;
+ }
+ }
+ int n()
+ {
+ X2<int, X0<int> > ngs;
+ N::X3<> b;
+ op(ngs, b);
+ return 0;
+ }
+
+}
diff --git a/test/SemaTemplate/friend.cpp b/test/SemaTemplate/friend.cpp
index 61ef1865da5d..99685f2396cf 100644
--- a/test/SemaTemplate/friend.cpp
+++ b/test/SemaTemplate/friend.cpp
@@ -12,3 +12,22 @@ void f() {
struct C0 {
friend struct A<int>;
};
+
+namespace PR6770 {
+ namespace N {
+ int f1(int);
+ }
+ using namespace N;
+
+ namespace M {
+ float f1(float);
+ }
+ using M::f1;
+
+ template<typename T> void f1(T, T);
+ template <class T>
+ void f() {
+ friend class f; // expected-error{{'friend' used outside of class}}
+ friend class f1; // expected-error{{ 'friend' used outside of class}}
+ }
+}
diff --git a/test/SemaTemplate/fun-template-def.cpp b/test/SemaTemplate/fun-template-def.cpp
index 1c9b232f6d36..309921c0a664 100644
--- a/test/SemaTemplate/fun-template-def.cpp
+++ b/test/SemaTemplate/fun-template-def.cpp
@@ -42,7 +42,7 @@ T f1(T t1, U u1, int i1)
dummy d1 = sizeof(t1); // expected-error {{no viable conversion}}
dummy d2 = offsetof(T, foo); // expected-error {{no viable conversion}}
dummy d3 = __alignof(u1); // expected-error {{no viable conversion}}
- i1 = typeid(t1); // expected-error {{incompatible type assigning}}
+ i1 = typeid(t1); // expected-error {{assigning to 'int' from incompatible type 'std::type_info const'}}
return u1;
}
diff --git a/test/SemaTemplate/injected-class-name.cpp b/test/SemaTemplate/injected-class-name.cpp
index 586be189b0ab..4c21d2585d32 100644
--- a/test/SemaTemplate/injected-class-name.cpp
+++ b/test/SemaTemplate/injected-class-name.cpp
@@ -48,3 +48,15 @@ namespace pr6326 {
};
template class A<int>;
}
+
+namespace ForwardDecls {
+ template<typename T>
+ struct X;
+
+ template<typename T>
+ struct X {
+ typedef T foo;
+ typedef X<T> xt;
+ typename xt::foo *t;
+ };
+}
diff --git a/test/SemaTemplate/instantiate-complete.cpp b/test/SemaTemplate/instantiate-complete.cpp
index 82cc320fd3c4..d854c9e6aacc 100644
--- a/test/SemaTemplate/instantiate-complete.cpp
+++ b/test/SemaTemplate/instantiate-complete.cpp
@@ -11,7 +11,8 @@ struct X {
// expected-error{{data member instantiated with function type 'int (int)'}} \
// expected-error{{data member instantiated with function type 'char (char)'}} \
// expected-error{{data member instantiated with function type 'short (short)'}} \
- // expected-error{{data member instantiated with function type 'float (float)'}}
+ // expected-error{{data member instantiated with function type 'float (float)'}} \
+ // expected-error{{data member instantiated with function type 'long (long)'}}
};
X<int> f() { return 0; }
@@ -43,7 +44,7 @@ void test_memptr(X<long> *p1, long X<long>::*pm1,
X<long(long)> *p2,
long (X<long(long)>::*pm2)(long)) {
(void)(p1->*pm1);
- (void)((p2->*pm2)(0));
+ (void)((p2->*pm2)(0)); // expected-note{{in instantiation of template class 'X<long (long)>' requested here}}
}
// Reference binding to a base
@@ -83,3 +84,18 @@ namespace PR6376 {
template struct Y<int, float>;
}
+
+namespace TemporaryObjectCopy {
+ // Make sure we instantiate classes when we create a temporary copy.
+ template<typename T>
+ struct X {
+ X(T);
+ };
+
+ template<typename T>
+ void f(T t) {
+ const X<int> &x = X<int>(t);
+ }
+
+ template void f(int);
+}
diff --git a/test/SemaTemplate/instantiate-default-assignment-operator.cpp b/test/SemaTemplate/instantiate-default-assignment-operator.cpp
index 5594d6c7d799..8b97f59e87ed 100644
--- a/test/SemaTemplate/instantiate-default-assignment-operator.cpp
+++ b/test/SemaTemplate/instantiate-default-assignment-operator.cpp
@@ -5,13 +5,13 @@ template<typename T> struct RefPtr {
RefPtr& operator=(const PassRefPtr<T>&);
};
-struct A { RefPtr<int> a; };
-struct B : RefPtr<float> { };
+struct A { RefPtr<int> a; }; // expected-note {{instantiation of member function 'RefPtr<int>::operator=' requested here}}
+struct B : RefPtr<float> { }; // expected-note {{in instantiation of member function 'RefPtr<float>::operator=' requested here}}
void f() {
A a1, a2;
- a1 = a2; // expected-note {{instantiation of member function 'RefPtr<int>::operator=' requested here}}
+ a1 = a2;
B b1, b2;
- b1 = b2; // expected-note {{in instantiation of member function 'RefPtr<float>::operator=' requested here}}
+ b1 = b2;
}
diff --git a/test/SemaTemplate/instantiate-expr-2.cpp b/test/SemaTemplate/instantiate-expr-2.cpp
index 4da4e713ec18..b91b398a80e3 100644
--- a/test/SemaTemplate/instantiate-expr-2.cpp
+++ b/test/SemaTemplate/instantiate-expr-2.cpp
@@ -193,3 +193,22 @@ namespace N12 {
void f0(int **a) { C::f0(a); }
}
+
+namespace N13 {
+ class A{
+ A(const A&);
+
+ public:
+ ~A();
+ A(int);
+ template<typename T> A &operator<<(const T&);
+ };
+
+ template<typename T>
+ void f(T t) {
+ A(17) << t;
+ }
+
+ template void f(int);
+
+}
diff --git a/test/SemaTemplate/instantiate-expr-5.cpp b/test/SemaTemplate/instantiate-expr-5.cpp
index 941dae44829a..6cdedda4d880 100644
--- a/test/SemaTemplate/instantiate-expr-5.cpp
+++ b/test/SemaTemplate/instantiate-expr-5.cpp
@@ -1,4 +1,38 @@
-// RUN: %clang_cc1 -fsyntax-only %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s
template <class A> int x(A x) { return x++; }
int y() { return x<int>(1); }
+
+namespace PR5880 {
+ template<typename T>
+ struct A {
+ static const int a = __builtin_offsetof(T, a.array[5].m); // expected-error{{error: no member named 'a' in 'HasM'}}
+ };
+ struct HasM {
+ float m;
+ };
+
+ struct ArrayOfHasM {
+ HasM array[10];
+ };
+
+ struct B { ArrayOfHasM a; };
+ A<B> x;
+ A<HasM> x2; // expected-note{{in instantiation of}}
+
+ template<typename T>
+ struct AnonymousUnion {
+ union {
+ int i;
+ float f;
+ };
+ };
+
+ template<typename T>
+ void test_anon_union() {
+ int array1[__builtin_offsetof(AnonymousUnion<T>, f) == 0? 1 : -1];
+ int array2[__builtin_offsetof(AnonymousUnion<int>, f) == 0? 1 : -1];
+ }
+
+ template void test_anon_union<int>();
+}
diff --git a/test/SemaTemplate/instantiate-function-1.cpp b/test/SemaTemplate/instantiate-function-1.cpp
index 6e0d71159004..1bda43000b2a 100644
--- a/test/SemaTemplate/instantiate-function-1.cpp
+++ b/test/SemaTemplate/instantiate-function-1.cpp
@@ -220,3 +220,8 @@ namespace test0 {
template <class T> class A { void foo(T array[10]); };
template class A<int>;
}
+
+namespace PR7016 {
+ template<typename T> void f() { T x = x; }
+ template void f<int>();
+}
diff --git a/test/SemaTemplate/instantiate-function-params.cpp b/test/SemaTemplate/instantiate-function-params.cpp
index ea8dd7061988..45de3425d2a2 100644
--- a/test/SemaTemplate/instantiate-function-params.cpp
+++ b/test/SemaTemplate/instantiate-function-params.cpp
@@ -3,13 +3,13 @@
// PR6619
template<bool C> struct if_c { };
template<typename T1> struct if_ {
- typedef if_c< static_cast<bool>(T1::value)> almost_type_; // expected-note 7{{in instantiation}}
+ typedef if_c< static_cast<bool>(T1::value)> almost_type_; // expected-note 5{{in instantiation}}
};
template <class Model, void (Model::*)()> struct wrap_constraints { };
template <class Model>
-inline char has_constraints_(Model* , // expected-note 4{{while substituting deduced template arguments into function template 'has_constraints_' [with }} \
+inline char has_constraints_(Model* , // expected-note 2{{while substituting deduced template arguments into function template 'has_constraints_' [with }} \
// expected-note 3{{candidate template ignored}}
- wrap_constraints<Model,&Model::constraints>* = 0); // expected-note 4{{in instantiation}}
+ wrap_constraints<Model,&Model::constraints>* = 0); // expected-note 2{{in instantiation}}
template <class Model> struct not_satisfied {
static const bool value = sizeof( has_constraints_((Model*)0) == 1); // expected-error 3{{no matching function}}
@@ -17,20 +17,18 @@ template <class Model> struct not_satisfied {
template <class ModelFn> struct requirement_;
template <void(*)()> struct instantiate {
};
-template <class Model> struct requirement_<void(*)(Model)> : if_< not_satisfied<Model> >::type { // expected-error 3{{no type named}} \
- // expected-note 7{{in instantiation}}
+template <class Model> struct requirement_<void(*)(Model)> : if_< not_satisfied<Model> >::type { // expected-note 5{{in instantiation}}
};
template <class Model> struct usage_requirements {
};
template < typename TT > struct InputIterator {
- typedef instantiate< & requirement_<void(*)(usage_requirements<InputIterator> x)>::failed> boost_concept_check1; // expected-note 2{{in instantiation}}
+ typedef instantiate< & requirement_<void(*)(usage_requirements<InputIterator> x)>::failed> boost_concept_check1; // expected-note {{in instantiation}}
};
-template < typename TT > struct ForwardIterator : InputIterator<TT> { // expected-note 2{{in instantiation}}
- typedef instantiate< & requirement_<void(*)(usage_requirements<ForwardIterator> x)>::failed> boost_concept_check2; // expected-note 2 {{in instantiation}}
+template < typename TT > struct ForwardIterator : InputIterator<TT> { // expected-note {{in instantiation}}
+ typedef instantiate< & requirement_<void(*)(usage_requirements<ForwardIterator> x)>::failed> boost_concept_check2; // expected-note {{in instantiation}}
};
-typedef instantiate< &requirement_<void(*)(ForwardIterator<char*> x)>::failed> boost_concept_checkX; // expected-error{{no member named}} \
-// expected-note 6{{in instantiation}}
+typedef instantiate< &requirement_<void(*)(ForwardIterator<char*> x)>::failed> boost_concept_checkX;// expected-note 3{{in instantiation}}
template<typename T> struct X0 { };
template<typename R, typename A1> struct X0<R(A1 param)> { };
@@ -55,3 +53,26 @@ void use_func_ptr() {
};
template void use_func_ptr<int, float, double>();
+
+namespace PR6990 {
+ template < typename , typename = int, typename = int > struct X1;
+ template <typename >
+ struct X2;
+
+ template <typename = int *, typename TokenT = int,
+ typename = int( X2<TokenT> &)>
+ struct X3
+ {
+ };
+
+ template <typename , typename P>
+ struct X3_base : X3< X1<int, P> >
+ {
+ protected: typedef X1< P> type;
+ X3<type> e;
+ };
+
+ struct r : X3_base<int, int>
+ {
+ };
+}
diff --git a/test/SemaTemplate/instantiate-local-class.cpp b/test/SemaTemplate/instantiate-local-class.cpp
index 72ad90a04f20..d57ba8a68288 100644
--- a/test/SemaTemplate/instantiate-local-class.cpp
+++ b/test/SemaTemplate/instantiate-local-class.cpp
@@ -13,11 +13,11 @@ template void f0<int>();
// PR5764
namespace PR5764 {
- class X {
+ struct X {
template <typename T>
void Bar() {
typedef T ValueType;
- class Y {
+ struct Y {
Y() { V = ValueType(); }
ValueType V;
diff --git a/test/SemaTemplate/instantiate-member-class.cpp b/test/SemaTemplate/instantiate-member-class.cpp
index 44f396e47af7..f1bdf3e1e6d5 100644
--- a/test/SemaTemplate/instantiate-member-class.cpp
+++ b/test/SemaTemplate/instantiate-member-class.cpp
@@ -18,8 +18,8 @@ X<int>::X *xi; // expected-error{{qualified reference to 'X' is a constructor na
X<float>::X *xf; // expected-error{{qualified reference to 'X' is a constructor name rather than a type wherever a constructor can be declared}}
void test_naming() {
- c1 = c2; // expected-error{{incompatible type assigning 'X<float>::C *', expected 'X<int>::C *'}}
- xi = xf; // expected-error{{incompatible type assigning}}
+ c1 = c2; // expected-error{{assigning to 'X<int>::C *' from incompatible type 'X<float>::C *'}}
+ xi = xf; // expected-error{{assigning to 'X<int>::X<int> *' from incompatible type 'X<float>::X<float> *'}}
// FIXME: error above doesn't print the type X<int>::X cleanly!
}
@@ -40,9 +40,9 @@ X<void>::D::E e2; // expected-note{{in instantiation of member class 'X<void>::D
// Redeclarations.
namespace test1 {
template <typename T> struct Registry {
- class node;
+ struct node;
static node *Head;
- class node {
+ struct node {
node(int v) { Head = this; }
};
};
@@ -64,6 +64,7 @@ namespace test2 {
template <typename T> class B {
class Foo;
class Foo {
+ public:
typedef int X;
};
typename Foo::X x;
diff --git a/test/SemaTemplate/instantiate-member-expr.cpp b/test/SemaTemplate/instantiate-member-expr.cpp
index f3a60679d176..188705ce2139 100644
--- a/test/SemaTemplate/instantiate-member-expr.cpp
+++ b/test/SemaTemplate/instantiate-member-expr.cpp
@@ -43,7 +43,7 @@ namespace test1 {
int a;
template<typename T> struct B : A<T> {
void f() {
- a = 0; // expected-error {{type 'test1::O' is not a direct or virtual base of ''B<int>''}}
+ a = 0; // expected-error {{'test1::O::a' is not a member of class 'test1::O::B<int>'}}
}
};
};
diff --git a/test/SemaTemplate/instantiate-member-initializers.cpp b/test/SemaTemplate/instantiate-member-initializers.cpp
index e0594347f262..45503b38b38d 100644
--- a/test/SemaTemplate/instantiate-member-initializers.cpp
+++ b/test/SemaTemplate/instantiate-member-initializers.cpp
@@ -10,8 +10,8 @@ A<int> a0;
A<void*> a1; // expected-note{{in instantiation of member function 'A<void *>::A' requested here}}
template<typename T> struct B {
- B() : b(1), // expected-warning {{member 'b' will be initialized after}}
- a(2) { } // expected-note {{field a}}
+ B() : b(1), // expected-warning {{field 'b' will be initialized after field 'a'}}
+ a(2) { }
int a;
int b;
@@ -21,6 +21,7 @@ B<int> b0; // expected-note {{in instantiation of member function 'B<int>::B' re
template <class T> struct AA { AA(int); };
template <class T> class BB : public AA<T> {
+public:
BB() : AA<T>(1) {}
};
BB<int> x;
diff --git a/test/SemaTemplate/instantiate-member-template.cpp b/test/SemaTemplate/instantiate-member-template.cpp
index c1260cf6a81e..ae8425e716ee 100644
--- a/test/SemaTemplate/instantiate-member-template.cpp
+++ b/test/SemaTemplate/instantiate-member-template.cpp
@@ -44,7 +44,7 @@ struct X1 {
template<typename U>
struct Inner3 {
- void f0(T t, U u) {
+ void f0(T t, U u) { // expected-note{{passing argument to parameter 't' here}}
(void)(t + u); // expected-error{{invalid operands}}
}
diff --git a/test/SemaTemplate/instantiate-method.cpp b/test/SemaTemplate/instantiate-method.cpp
index 357ea2617759..363115d1844e 100644
--- a/test/SemaTemplate/instantiate-method.cpp
+++ b/test/SemaTemplate/instantiate-method.cpp
@@ -5,7 +5,7 @@ public:
void f(T x); // expected-error{{argument may not have 'void' type}}
void g(T*);
- static int h(T, T); // expected-error 2{{argument may not have 'void' type}}
+ static int h(T, T); // expected-error {{argument may not have 'void' type}}
};
int identity(int x) { return x; }
@@ -117,3 +117,61 @@ struct X3 {
template struct X3<double>;
+
+// Don't try to instantiate this, it's invalid.
+namespace test1 {
+ template <class T> class A {};
+ template <class T> class B {
+ void foo(A<test1::Undeclared> &a) // expected-error {{no member named 'Undeclared' in namespace 'test1'}}
+ {}
+ };
+ template class B<int>;
+}
+
+namespace PR6947 {
+ template< class T >
+ struct X {
+ int f0( )
+ {
+ typedef void ( X::*impl_fun_ptr )( );
+ impl_fun_ptr pImpl = &X::template
+ f0_impl1<int>;
+ }
+ private:
+ int f1() {
+ }
+ template< class Processor>
+ void f0_impl1( )
+ {
+ }
+ };
+
+ char g0() {
+ X<int> pc;
+ pc.f0();
+ }
+
+}
+
+namespace PR7022 {
+ template <typename >
+ struct X1
+ {
+ typedef int state_t( );
+ state_t g ;
+ };
+
+ template < typename U = X1<int> > struct X2
+ {
+ X2( U = U())
+ {
+ }
+ };
+
+ void m(void)
+ {
+ typedef X2<> X2_type;
+ X2_type c;
+ }
+
+}
diff --git a/test/SemaTemplate/instantiate-non-type-template-parameter.cpp b/test/SemaTemplate/instantiate-non-type-template-parameter.cpp
index 414e62b13a03..cbadcde2c1c1 100644
--- a/test/SemaTemplate/instantiate-non-type-template-parameter.cpp
+++ b/test/SemaTemplate/instantiate-non-type-template-parameter.cpp
@@ -9,6 +9,28 @@ public:
}
};
-int main(int argc, char *argv[]) {
+void test_stringswitch(int argc, char *argv[]) {
(void)StringSwitch<int>();
}
+
+namespace PR6986 {
+ template<class Class,typename Type,Type Class::*>
+ struct non_const_member_base
+ {
+ };
+
+ template<class Class,typename Type,Type Class::*PtrToMember>
+ struct member: non_const_member_base<Class,Type,PtrToMember>
+ {
+ };
+
+ struct test_class
+ {
+ int int_member;
+ };
+ typedef member< test_class,const int,&test_class::int_member > ckey_m;
+ void test()
+ {
+ ckey_m m;
+ }
+}
diff --git a/test/SemaTemplate/instantiate-typedef.cpp b/test/SemaTemplate/instantiate-typedef.cpp
index bb168a1c932e..4e6cd24111c4 100644
--- a/test/SemaTemplate/instantiate-typedef.cpp
+++ b/test/SemaTemplate/instantiate-typedef.cpp
@@ -11,6 +11,5 @@ add_pointer<float>::type test2(int * ptr) {
return ptr; // expected-error{{cannot initialize return object of type 'add_pointer<float>::type' (aka 'float *') with an lvalue of type 'int *'}}
}
-add_pointer<int&>::type // expected-note{{in instantiation of template class 'add_pointer<int &>' requested here}} \
-// expected-error {{no type named 'type' in 'add_pointer<int &>'}}
+add_pointer<int&>::type // expected-note{{in instantiation of template class 'add_pointer<int &>' requested here}}
test3();
diff --git a/test/SemaTemplate/instantiate-using-decl.cpp b/test/SemaTemplate/instantiate-using-decl.cpp
index a4394aa21f6e..257904490daa 100644
--- a/test/SemaTemplate/instantiate-using-decl.cpp
+++ b/test/SemaTemplate/instantiate-using-decl.cpp
@@ -38,7 +38,7 @@ namespace test1 {
using Base2::Visit;
};
- class Knot : JoinVisitor<Knot> {
+ class Knot : public JoinVisitor<Knot> {
};
void test() {
diff --git a/test/SemaTemplate/instantiation-depth.cpp b/test/SemaTemplate/instantiation-depth.cpp
index f48ede9c44cf..a2b9d2eb1513 100644
--- a/test/SemaTemplate/instantiation-depth.cpp
+++ b/test/SemaTemplate/instantiation-depth.cpp
@@ -1,8 +1,10 @@
-// RUN: %clang_cc1 -fsyntax-only -ftemplate-depth 5 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -ftemplate-depth 5 -ftemplate-backtrace-limit 4 %s
-template<typename T> struct X : X<T*> { }; // expected-error{{recursive template instantiation exceeded maximum depth of 5}} \
-// expected-note{{use -ftemplate-depth-N to increase recursive template instantiation depth}} \
-// expected-note 5 {{instantiation of template class}}
+template<typename T> struct X : X<T*> { }; \
+// expected-error{{recursive template instantiation exceeded maximum depth of 5}} \
+// expected-note 3 {{instantiation of template class}} \
+// expected-note {{skipping 2 contexts in backtrace}} \
+// expected-note {{use -ftemplate-depth-N to increase recursive template instantiation depth}}
void test() {
(void)sizeof(X<int>); // expected-note {{instantiation of template class}}
diff --git a/test/SemaTemplate/nested-name-spec-template.cpp b/test/SemaTemplate/nested-name-spec-template.cpp
index 1691db74a115..9d25a051e8a8 100644
--- a/test/SemaTemplate/nested-name-spec-template.cpp
+++ b/test/SemaTemplate/nested-name-spec-template.cpp
@@ -51,3 +51,16 @@ struct TestA {
typedef typename N::template B<T>::type type; // expected-error{{'B' following the 'template' keyword does not refer to a template}} \
// expected-error{{expected member name}}
};
+
+// Reduced from a Boost failure.
+namespace test1 {
+ template <class T> struct pair {
+ T x;
+ T y;
+
+ static T pair<T>::* const mem_array[2];
+ };
+
+ template <class T>
+ T pair<T>::* const pair<T>::mem_array[2] = { &pair<T>::x, &pair<T>::y };
+}
diff --git a/test/SemaTemplate/qualified-id.cpp b/test/SemaTemplate/qualified-id.cpp
index 2e3a826ce894..29eab89d84f5 100644
--- a/test/SemaTemplate/qualified-id.cpp
+++ b/test/SemaTemplate/qualified-id.cpp
@@ -21,6 +21,7 @@ namespace test1 {
namespace test2 {
class Impl {
+ public:
int foo();
};
template <class T> class Magic : public Impl {
diff --git a/test/SemaTemplate/temp_arg.cpp b/test/SemaTemplate/temp_arg.cpp
index 80bbda785d05..5a4c8fc16fd6 100644
--- a/test/SemaTemplate/temp_arg.cpp
+++ b/test/SemaTemplate/temp_arg.cpp
@@ -2,7 +2,7 @@
template<typename T,
int I,
template<typename> class TT>
- class A; // expected-note 2 {{template is declared here}}
+ class A; // expected-note 3 {{template is declared here}}
template<typename> class X;
@@ -10,6 +10,7 @@ A<int, 0, X> * a1;
A<float, 1, X, double> *a2; // expected-error{{too many template arguments for class template 'A'}}
A<float, 1> *a3; // expected-error{{too few template arguments for class template 'A'}}
+A a3; // expected-error{{use of class template A requires template arguments}}
namespace test0 {
template <class t> class foo {};
diff --git a/test/SemaTemplate/temp_arg_nontype.cpp b/test/SemaTemplate/temp_arg_nontype.cpp
index 6e4f751d47d1..d351eb458838 100644
--- a/test/SemaTemplate/temp_arg_nontype.cpp
+++ b/test/SemaTemplate/temp_arg_nontype.cpp
@@ -36,19 +36,19 @@ A<X(17, 42)> *a11; // expected-error{{non-type template argument of type 'X' mus
float f(float);
-float g(float);
-double g(double);
+float g(float); // expected-note 2{{candidate function}}
+double g(double); // expected-note 2{{candidate function}}
int h(int);
float h2(float);
-template<int fp(int)> struct A3; // expected-note 2{{template parameter is declared here}}
+template<int fp(int)> struct A3; // expected-note 1{{template parameter is declared here}}
A3<h> *a14_1;
A3<&h> *a14_2;
A3<f> *a14_3;
A3<&f> *a14_4;
A3<h2> *a14_6; // expected-error{{non-type template argument of type 'float (float)' cannot be converted to a value of type 'int (*)(int)'}}
-A3<g> *a14_7; // expected-error{{overloaded function cannot be resolved to a non-type template parameter of type 'int (*)(int)'}}
+A3<g> *a14_7; // expected-error{{address of overloaded function 'g' does not match required type 'int (int)'}}
struct Y { } y;
@@ -61,11 +61,11 @@ A4<*X_volatile_ptr> *a15_2; // expected-error{{non-type template argument does n
A4<y> *15_3; // expected-error{{non-type template parameter of reference type 'X const &' cannot bind to template argument of type 'struct Y'}} \
// FIXME: expected-error{{expected unqualified-id}}
-template<int (&fr)(int)> struct A5; // expected-note 2{{template parameter is declared here}}
+template<int (&fr)(int)> struct A5; // expected-note{{template parameter is declared here}}
A5<h> *a16_1;
A5<f> *a16_3;
A5<h2> *a16_6; // expected-error{{non-type template parameter of reference type 'int (&)(int)' cannot bind to template argument of type 'float (float)'}}
-A5<g> *a14_7; // expected-error{{overloaded function cannot be resolved to a non-type template parameter of type 'int (&)(int)'}}
+A5<g> *a14_7; // expected-error{{address of overloaded function 'g' does not match required type 'int (int)'}}
struct Z {
int foo(int);
@@ -176,3 +176,30 @@ namespace PR6723 {
f<512>(arr512); // expected-error{{no matching function for call}}
}
}
+
+// Check that we instantiate declarations whose addresses are taken
+// for non-type template arguments.
+namespace EntityReferenced {
+ template<typename T, void (*)(T)> struct X { };
+
+ template<typename T>
+ struct Y {
+ static void f(T x) {
+ x = 1; // expected-error{{assigning to 'int *' from incompatible type 'int'}}
+ }
+ };
+
+ void g() {
+ typedef X<int*, Y<int*>::f> x; // expected-note{{in instantiation of}}
+ }
+}
+
+namespace PR6964 {
+ template <typename ,int, int = 9223372036854775807L > // expected-warning 2{{non-type template argument value '9223372036854775807' truncated to '-1' for template parameter of type 'int'}} \
+ // expected-note 2{{template parameter is declared here}}
+ struct as_nview { };
+
+ template <typename Sequence, int I0>
+ struct as_nview<Sequence, I0> // expected-note{{while checking a default template argument used here}}
+ { };
+}
diff --git a/test/SemaTemplate/temp_arg_type.cpp b/test/SemaTemplate/temp_arg_type.cpp
index a1db3f8057ac..3876c256455d 100644
--- a/test/SemaTemplate/temp_arg_type.cpp
+++ b/test/SemaTemplate/temp_arg_type.cpp
@@ -1,16 +1,26 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
-template<typename T> class A; // expected-note 2 {{template parameter is declared here}}
+template<typename T> class A; // expected-note 2 {{template parameter is declared here}} expected-note{{template is declared here}}
// [temp.arg.type]p1
A<0> *a1; // expected-error{{template argument for template type parameter must be a type}}
-A<A> *a2; // expected-error{{template argument for template type parameter must be a type}}
+A<A> *a2; // expected-error{{use of class template A requires template arguments}}
A<int> *a3;
A<int()> *a4;
A<int(float)> *a5;
A<A<int> > *a6;
+// Pass an overloaded function template:
+template<typename T> void function_tpl(T);
+A<function_tpl> a7; // expected-error{{template argument for template type parameter must be a type}}
+
+// Pass a qualified name:
+namespace ns {
+template<typename T> class B {}; // expected-note{{template is declared here}}
+}
+A<ns::B> a8; // expected-error{{use of class template ns::B requires template arguments}}
+
// [temp.arg.type]p2
void f() {
class X { };
@@ -18,7 +28,15 @@ void f() {
}
struct { int x; } Unnamed; // expected-note{{unnamed type used in template argument was declared here}}
-A<__typeof__(Unnamed)> *a7; // expected-error{{template argument uses unnamed type}}
+A<__typeof__(Unnamed)> *a9; // expected-error{{template argument uses unnamed type}}
+
+template<typename T, unsigned N>
+struct Array {
+ typedef struct { T x[N]; } type;
+};
+
+template<typename T> struct A1 { };
+A1<Array<int, 17>::type> ax;
// FIXME: [temp.arg.type]p3. The check doesn't really belong here (it
// belongs somewhere in the template instantiation section).
diff --git a/test/SemaTemplate/template-decl-fail.cpp b/test/SemaTemplate/template-decl-fail.cpp
index eca0f58831a9..ad134cdf225c 100644
--- a/test/SemaTemplate/template-decl-fail.cpp
+++ b/test/SemaTemplate/template-decl-fail.cpp
@@ -4,5 +4,7 @@ template<typename T> typedef T X; // expected-error{{typedef cannot be a templat
template<typename T>
enum t0 { A = T::x }; // expected-error{{enumeration cannot be a template}} \
- // expected-error{{declaration does not declare anything}}
+ // expected-warning{{declaration does not declare anything}}
+enum e0 {};
+template<int x> enum e0 f0(int a=x) {}
diff --git a/test/SemaTemplate/typename-specifier-4.cpp b/test/SemaTemplate/typename-specifier-4.cpp
index 280a1b4c3957..8dfb60d70718 100644
--- a/test/SemaTemplate/typename-specifier-4.cpp
+++ b/test/SemaTemplate/typename-specifier-4.cpp
@@ -113,6 +113,6 @@ namespace PR6463 {
// FIXME: Improve source location info here.
template<typename T>
typename A<T>::type& A<T>::a() { // expected-error{{found in multiple base classes}}
- return x; // expected-error{{undeclared identifier}}
+ return x;
}
}
diff --git a/test/SemaTemplate/typename-specifier.cpp b/test/SemaTemplate/typename-specifier.cpp
index 42766a0620b8..3f6fe343f507 100644
--- a/test/SemaTemplate/typename-specifier.cpp
+++ b/test/SemaTemplate/typename-specifier.cpp
@@ -42,13 +42,10 @@ namespace N {
}
N::X<N::A>::type *ip4 = &i;
-N::X<N::B>::type *ip5 = &i; // expected-note{{in instantiation of template class 'N::X<N::B>' requested here}} \
-// expected-error{{no type named 'type' in}}
-N::X<N::C>::type *ip6 = &i; // expected-note{{in instantiation of template class 'N::X<N::C>' requested here}} \
-// expected-error{{no type named 'type' in}}
+N::X<N::B>::type *ip5 = &i; // expected-note{{in instantiation of template class 'N::X<N::B>' requested here}}
+N::X<N::C>::type *ip6 = &i; // expected-note{{in instantiation of template class 'N::X<N::C>' requested here}}
-N::X<int>::type fail1; // expected-note{{in instantiation of template class 'N::X<int>' requested here}} \
-// expected-error{{no type named 'type' in}}
+N::X<int>::type fail1; // expected-note{{in instantiation of template class 'N::X<int>' requested here}}
template<typename T>
struct Y {
@@ -69,7 +66,5 @@ struct C {
};
::Y<A>::type ip7 = &i;
-::Y<B>::type ip8 = &i; // expected-note{{in instantiation of template class 'Y<B>' requested here}} \
-// expected-error{{no type named 'type' in}}
-::Y<C>::type ip9 = &i; // expected-note{{in instantiation of template class 'Y<C>' requested here}} \
-// expected-error{{no type named 'type' in}}
+::Y<B>::type ip8 = &i; // expected-note{{in instantiation of template class 'Y<B>' requested here}}
+::Y<C>::type ip9 = &i; // expected-note{{in instantiation of template class 'Y<C>' requested here}}