summaryrefslogtreecommitdiffstats
path: root/test/SemaTemplate
diff options
context:
space:
mode:
Diffstat (limited to 'test/SemaTemplate')
-rw-r--r--test/SemaTemplate/class-template-id.cpp5
-rw-r--r--test/SemaTemplate/constructor-template.cpp12
-rw-r--r--test/SemaTemplate/friend-template.cpp126
-rw-r--r--test/SemaTemplate/instantiate-default-assignment-operator.cpp17
-rw-r--r--test/SemaTemplate/instantiate-enum-2.cpp9
-rw-r--r--test/SemaTemplate/instantiate-exception-spec.cpp11
-rw-r--r--test/SemaTemplate/instantiate-expr-1.cpp18
-rw-r--r--test/SemaTemplate/instantiate-expr-4.cpp18
-rw-r--r--test/SemaTemplate/instantiate-function-1.mm2
-rw-r--r--test/SemaTemplate/instantiate-method.cpp4
-rw-r--r--test/SemaTemplate/instantiate-objc-1.mm2
-rw-r--r--test/SemaTemplate/instantiate-static-var.cpp20
-rw-r--r--test/SemaTemplate/instantiate-using-decl.cpp63
-rw-r--r--test/SemaTemplate/qualified-id.cpp11
-rw-r--r--test/SemaTemplate/template-class-traits.cpp8
-rw-r--r--test/SemaTemplate/virtual-member-functions.cpp22
16 files changed, 263 insertions, 85 deletions
diff --git a/test/SemaTemplate/class-template-id.cpp b/test/SemaTemplate/class-template-id.cpp
index e74a6f8..98ccbe7 100644
--- a/test/SemaTemplate/class-template-id.cpp
+++ b/test/SemaTemplate/class-template-id.cpp
@@ -36,3 +36,8 @@ namespace N {
N::C<int> c1;
typedef N::C<float> c2;
+
+// PR5655
+template<typename T> struct Foo { }; // expected-note{{template is declared here}}
+
+void f(void) { Foo bar; } // expected-error{{without a template argument list}}
diff --git a/test/SemaTemplate/constructor-template.cpp b/test/SemaTemplate/constructor-template.cpp
index 203977e..0b6916f 100644
--- a/test/SemaTemplate/constructor-template.cpp
+++ b/test/SemaTemplate/constructor-template.cpp
@@ -82,3 +82,15 @@ X4 test_X4(bool Cond, X4 x4) {
X4 b(x4); // okay, copy constructor
return X4(); // expected-error{{no viable conversion}}
}
+
+// Instantiation of a non-dependent use of a constructor
+struct DefaultCtorHasDefaultArg {
+ explicit DefaultCtorHasDefaultArg(int i = 17);
+};
+
+template<typename T>
+void default_ctor_inst() {
+ DefaultCtorHasDefaultArg def;
+}
+
+template void default_ctor_inst<int>();
diff --git a/test/SemaTemplate/friend-template.cpp b/test/SemaTemplate/friend-template.cpp
index 84a8e89..98992f6 100644
--- a/test/SemaTemplate/friend-template.cpp
+++ b/test/SemaTemplate/friend-template.cpp
@@ -1,23 +1,20 @@
// RUN: clang-cc -fsyntax-only -verify %s
// PR5057
-namespace std {
- class X {
- public:
- template<typename T>
- friend struct Y;
- };
-}
-
-namespace std {
- template<typename T>
- struct Y
- {
- };
+namespace test0 {
+ namespace std {
+ class X {
+ public:
+ template<typename T> friend struct Y;
+ };
+ }
+
+ namespace std {
+ template<typename T> struct Y {};
+ }
}
-
-namespace N {
+namespace test1 {
template<typename T> void f1(T) { } // expected-note{{here}}
class X {
@@ -30,64 +27,73 @@ namespace N {
}
// PR4768
-template<typename T>
-struct X0 {
- template<typename U> friend struct X0;
-};
-
-template<typename T>
-struct X0<T*> {
- template<typename U> friend struct X0;
-};
+namespace test2 {
+ template<typename T> struct X0 {
+ template<typename U> friend struct X0;
+ };
+
+ template<typename T> struct X0<T*> {
+ template<typename U> friend struct X0;
+ };
-template<>
-struct X0<int> {
- template<typename U> friend struct X0;
-};
+ template<> struct X0<int> {
+ template<typename U> friend struct X0;
+ };
-template<typename T>
-struct X1 {
- template<typename U> friend void f2(U);
- template<typename U> friend void f3(U);
-};
+ template<typename T> struct X1 {
+ template<typename U> friend void f2(U);
+ template<typename U> friend void f3(U);
+ };
-template<typename U> void f2(U);
+ template<typename U> void f2(U);
-X1<int> x1i;
-X0<int*> x0ip;
+ X1<int> x1i;
+ X0<int*> x0ip;
-template<> void f2(int);
+ template<> void f2(int);
-// FIXME: Should this declaration of f3 be required for the specialization of
-// f3<int> (further below) to work? GCC and EDG don't require it, we do...
-template<typename U> void f3(U);
+ // FIXME: Should this declaration of f3 be required for the specialization of
+ // f3<int> (further below) to work? GCC and EDG don't require it, we do...
+ template<typename U> void f3(U);
-template<> void f3(int);
+ template<> void f3(int);
+}
// PR5332
-template <typename T>
-class Foo {
- template <typename U>
- friend class Foo;
-};
+namespace test3 {
+ template <typename T> class Foo {
+ template <typename U>
+ friend class Foo;
+ };
+
+ Foo<int> foo;
+
+ template<typename T, T Value> struct X2a;
-Foo<int> foo;
+ template<typename T, int Size> struct X2b;
-template<typename T, T Value>
-struct X2a;
+ template<typename T>
+ class X3 {
+ template<typename U, U Value> friend struct X2a;
+ template<typename U, T Value> friend struct X2b;
+ };
-template<typename T, int Size>
-struct X2b;
+ X3<int> x3i; // okay
-template<typename T>
-class X3 {
- template<typename U, U Value>
- friend struct X2a;
+ X3<long> x3l; // FIXME: should cause an instantiation-time failure
+}
- template<typename U, T Value>
- friend struct X2b;
-};
+// PR5716
+namespace test4 {
+ template<typename> struct A {
+ template<typename T> friend void f(const A<T>&);
+ };
-X3<int> x3i; // okay
+ template<typename T> void f(const A<T>&) {
+ int a[sizeof(T) ? -1 : -1]; // expected-error {{array size is negative}}
+ }
-X3<long> x3l; // FIXME: should cause an instantiation-time failure
+ void f() {
+ f(A<int>()); // expected-note {{in instantiation of function template specialization}}
+ }
+}
diff --git a/test/SemaTemplate/instantiate-default-assignment-operator.cpp b/test/SemaTemplate/instantiate-default-assignment-operator.cpp
new file mode 100644
index 0000000..b0ac078
--- /dev/null
+++ b/test/SemaTemplate/instantiate-default-assignment-operator.cpp
@@ -0,0 +1,17 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+template<typename> struct PassRefPtr { };
+template<typename T> struct RefPtr {
+ RefPtr& operator=(const RefPtr&) { int a[sizeof(T) ? -1 : -1];} // expected-error 2 {{array size is negative}}
+ RefPtr& operator=(const PassRefPtr<T>&);
+};
+
+struct A { RefPtr<int> a; };
+struct B : RefPtr<float> { };
+
+void f() {
+ A a1, a2;
+ a1 = a2; // expected-note {{instantiation of member function 'RefPtr<int>::operator=' requested here}}
+
+ B b1, b2;
+ b1 = b2; // expected-note {{in instantiation of member function 'RefPtr<float>::operator=' requested here}}
+}
diff --git a/test/SemaTemplate/instantiate-enum-2.cpp b/test/SemaTemplate/instantiate-enum-2.cpp
new file mode 100644
index 0000000..2b56a03
--- /dev/null
+++ b/test/SemaTemplate/instantiate-enum-2.cpp
@@ -0,0 +1,9 @@
+// RUN: clang-cc %s -fsyntax-only -verify
+
+template<int IntBits> struct X {
+ enum {
+ IntShift = (unsigned long long)IntBits,
+ ShiftedIntMask = (1 << IntShift)
+ };
+};
+X<1> x;
diff --git a/test/SemaTemplate/instantiate-exception-spec.cpp b/test/SemaTemplate/instantiate-exception-spec.cpp
new file mode 100644
index 0000000..31db448
--- /dev/null
+++ b/test/SemaTemplate/instantiate-exception-spec.cpp
@@ -0,0 +1,11 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+// FIXME: the "note" should be down at the call site!
+template<typename T> void f1(T*) throw(T); // expected-error{{incomplete type 'struct Incomplete' is not allowed in exception specification}} \
+ // expected-note{{instantiation of}}
+struct Incomplete; // expected-note{{forward}}
+
+void test_f1(Incomplete *incomplete_p, int *int_p) {
+ f1(int_p);
+ f1(incomplete_p);
+}
diff --git a/test/SemaTemplate/instantiate-expr-1.cpp b/test/SemaTemplate/instantiate-expr-1.cpp
index fb88213..1cd55d9 100644
--- a/test/SemaTemplate/instantiate-expr-1.cpp
+++ b/test/SemaTemplate/instantiate-expr-1.cpp
@@ -94,3 +94,21 @@ struct Addable {
void test_add(Addable &a) {
add(a);
}
+
+struct CallOperator {
+ int &operator()(int);
+ double &operator()(double);
+};
+
+template<typename Result, typename F, typename Arg1>
+Result test_call_operator(F f, Arg1 arg1) {
+ // PR5266: non-dependent invocations of a function call operator.
+ CallOperator call_op;
+ int &ir = call_op(17);
+ return f(arg1);
+}
+
+void test_call_operator(CallOperator call_op, int i, double d) {
+ int &ir = test_call_operator<int&>(call_op, i);
+ double &dr = test_call_operator<double&>(call_op, d);
+}
diff --git a/test/SemaTemplate/instantiate-expr-4.cpp b/test/SemaTemplate/instantiate-expr-4.cpp
index cd74a21..b99ec33 100644
--- a/test/SemaTemplate/instantiate-expr-4.cpp
+++ b/test/SemaTemplate/instantiate-expr-4.cpp
@@ -96,6 +96,18 @@ template struct Delete0<int*>;
template struct Delete0<X*>;
template struct Delete0<int>; // expected-note{{instantiation}}
+namespace PR5755 {
+ template <class T>
+ void Foo() {
+ char* p = 0;
+ delete[] p;
+ }
+
+ void Test() {
+ Foo<int>();
+ }
+}
+
// ---------------------------------------------------------------------
// throw expressions
// ---------------------------------------------------------------------
@@ -185,7 +197,7 @@ template struct InitList2<APair, int*, double*>; // expected-note{{instantiation
template<typename T, typename Result>
struct DotMemRef0 {
void f(T t) {
- Result result = t.m; // expected-error{{cannot be initialized}}
+ Result result = t.m; // expected-error{{non-const lvalue reference to type}}
}
};
@@ -207,7 +219,7 @@ template struct DotMemRef0<MemInt, float&>; // expected-note{{instantiation}}
template<typename T, typename Result>
struct ArrowMemRef0 {
void f(T t) {
- Result result = t->m; // expected-error 2{{cannot be initialized}}
+ Result result = t->m; // expected-error 2{{non-const lvalue reference}}
}
};
@@ -269,7 +281,7 @@ template struct ThisMemberFuncCall0<int&>;
template<typename T>
struct NonDepMemberCall0 {
void foo(HasMemFunc0<int&> x) {
- T result = x.f(); // expected-error{{initialized}}
+ T result = x.f(); // expected-error{{non-const lvalue reference}}
}
};
diff --git a/test/SemaTemplate/instantiate-function-1.mm b/test/SemaTemplate/instantiate-function-1.mm
index c119ab5..aa4b941 100644
--- a/test/SemaTemplate/instantiate-function-1.mm
+++ b/test/SemaTemplate/instantiate-function-1.mm
@@ -1,4 +1,4 @@
-// RUN: clang-cc -fsyntax-only -verify %s
+// RUN: clang -cc1 -fsyntax-only -verify %s
// XFAIL: *
template<typename T> struct Member0 {
diff --git a/test/SemaTemplate/instantiate-method.cpp b/test/SemaTemplate/instantiate-method.cpp
index 2351d88..231e281 100644
--- a/test/SemaTemplate/instantiate-method.cpp
+++ b/test/SemaTemplate/instantiate-method.cpp
@@ -95,9 +95,7 @@ struct X0 : X0Base {
template<typename U>
struct X1 : X0<U> {
int &f2() {
- // FIXME: We should be able to do this lookup and diagnose the error
- // *despite* the fact that we can't decide the relationship yet.
- return X0Base::f(); // expected-FIXME-error{{call to non-static member function without an object argument}}
+ return X0Base::f();
}
};
diff --git a/test/SemaTemplate/instantiate-objc-1.mm b/test/SemaTemplate/instantiate-objc-1.mm
index 829acb2..093be4e 100644
--- a/test/SemaTemplate/instantiate-objc-1.mm
+++ b/test/SemaTemplate/instantiate-objc-1.mm
@@ -1,4 +1,4 @@
-// RUN: clang-cc -fsyntax-only -verify %s
+// RUN: clang -cc1 -fsyntax-only -verify %s
// Obj-C string literal expressions
template <typename T> struct StringTest {
diff --git a/test/SemaTemplate/instantiate-static-var.cpp b/test/SemaTemplate/instantiate-static-var.cpp
index 452fccf..d4a7008 100644
--- a/test/SemaTemplate/instantiate-static-var.cpp
+++ b/test/SemaTemplate/instantiate-static-var.cpp
@@ -72,3 +72,23 @@ void Test() {
Z1<Y2<X2>::value> x2;
int y2[Y2<X2>::value];
}
+
+// PR5672
+template <int n>
+struct X3 {};
+
+class Y3 {
+ public:
+ ~Y3(); // The error isn't triggered without this dtor.
+
+ void Foo(X3<1>);
+};
+
+template <typename T>
+struct SizeOf {
+ static const int value = sizeof(T);
+};
+
+void MyTest3() {
+ Y3().Foo(X3<SizeOf<char>::value>());
+}
diff --git a/test/SemaTemplate/instantiate-using-decl.cpp b/test/SemaTemplate/instantiate-using-decl.cpp
index a1cf355..de66f79 100644
--- a/test/SemaTemplate/instantiate-using-decl.cpp
+++ b/test/SemaTemplate/instantiate-using-decl.cpp
@@ -1,20 +1,49 @@
// RUN: clang-cc -fsyntax-only -verify %s
-namespace N { }
-
-template<typename T>
-struct A {
- void f();
-};
-
-template<typename T>
-struct B : A<T> {
- using A<T>::f;
-
- void g() {
- using namespace N;
- f();
- }
-};
+namespace test0 {
+ namespace N { }
+
+ template<typename T>
+ struct A {
+ void f();
+ };
+
+ template<typename T>
+ struct B : A<T> {
+ using A<T>::f;
+
+ void g() {
+ using namespace N;
+ f();
+ }
+ };
+
+ template struct B<int>;
+}
-template struct B<int>;
+namespace test1 {
+ template <class Derived> struct Visitor1 {
+ void Visit(struct Object1*);
+ };
+ template <class Derived> struct Visitor2 {
+ void Visit(struct Object2*); // expected-note {{candidate function}}
+ };
+
+ template <class Derived> struct JoinVisitor
+ : Visitor1<Derived>, Visitor2<Derived> {
+ typedef Visitor1<Derived> Base1;
+ typedef Visitor2<Derived> Base2;
+
+ void Visit(struct Object1*); // expected-note {{candidate function}}
+ using Base2::Visit;
+ };
+
+ class Knot : JoinVisitor<Knot> {
+ };
+
+ void test() {
+ Knot().Visit((struct Object1*) 0);
+ Knot().Visit((struct Object2*) 0);
+ Knot().Visit((struct Object3*) 0); // expected-error {{no matching member function for call}}
+ }
+}
diff --git a/test/SemaTemplate/qualified-id.cpp b/test/SemaTemplate/qualified-id.cpp
index a07f05c..ab57950 100644
--- a/test/SemaTemplate/qualified-id.cpp
+++ b/test/SemaTemplate/qualified-id.cpp
@@ -18,3 +18,14 @@ namespace test1 {
}
};
}
+
+namespace test2 {
+ class Impl {
+ int foo();
+ };
+ template <class T> class Magic : public Impl {
+ int foo() {
+ return Impl::foo();
+ }
+ };
+}
diff --git a/test/SemaTemplate/template-class-traits.cpp b/test/SemaTemplate/template-class-traits.cpp
new file mode 100644
index 0000000..7cf2004
--- /dev/null
+++ b/test/SemaTemplate/template-class-traits.cpp
@@ -0,0 +1,8 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+#define T(b) (b) ? 1 : -1
+#define F(b) (b) ? -1 : 1
+
+struct HasVirt { virtual void a(); };
+template<class T> struct InheritPolymorph : HasVirt {};
+int t01[T(__is_polymorphic(InheritPolymorph<int>))];
+
diff --git a/test/SemaTemplate/virtual-member-functions.cpp b/test/SemaTemplate/virtual-member-functions.cpp
new file mode 100644
index 0000000..486c8b2
--- /dev/null
+++ b/test/SemaTemplate/virtual-member-functions.cpp
@@ -0,0 +1,22 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+namespace PR5557 {
+template <class T> struct A {
+ A();
+ virtual int a(T x);
+};
+template<class T> A<T>::A() {}
+template<class T> int A<T>::a(T x) {
+ return *x; // expected-error{{requires pointer operand}}
+}
+
+A<int> x; // expected-note{{instantiation}}
+
+template<typename T>
+struct X {
+ virtual void f();
+};
+
+template<>
+void X<int>::f() { }
+}
OpenPOWER on IntegriCloud