summaryrefslogtreecommitdiffstats
path: root/test/SemaTemplate
diff options
context:
space:
mode:
Diffstat (limited to 'test/SemaTemplate')
-rw-r--r--test/SemaTemplate/current-instantiation.cpp9
-rw-r--r--test/SemaTemplate/default-arguments-cxx0x.cpp26
-rw-r--r--test/SemaTemplate/dependent-names.cpp70
-rw-r--r--test/SemaTemplate/dependent-sized_array.cpp17
-rw-r--r--test/SemaTemplate/destructor-template.cpp7
-rw-r--r--test/SemaTemplate/instantiate-function-1.cpp3
-rw-r--r--test/SemaTemplate/instantiate-member-template.cpp15
-rw-r--r--test/SemaTemplate/instantiate-method.cpp23
-rw-r--r--test/SemaTemplate/instantiate-static-var.cpp36
-rw-r--r--test/SemaTemplate/instantiation-depth.cpp2
-rw-r--r--test/SemaTemplate/nested-name-spec-template.cpp2
-rw-r--r--test/SemaTemplate/overload-uneval.cpp42
-rw-r--r--test/SemaTemplate/qualified-id.cpp11
-rw-r--r--test/SemaTemplate/temp_arg_nontype.cpp9
-rw-r--r--test/SemaTemplate/temp_explicit.cpp17
15 files changed, 282 insertions, 7 deletions
diff --git a/test/SemaTemplate/current-instantiation.cpp b/test/SemaTemplate/current-instantiation.cpp
index a1d9fcb..fe2c558 100644
--- a/test/SemaTemplate/current-instantiation.cpp
+++ b/test/SemaTemplate/current-instantiation.cpp
@@ -142,3 +142,12 @@ struct X0<T*, U*> {
void g8(typename ::X0<typename X0<T_type*, U*>::X2::my_T_type*, U_type*>::X2::my_T_type&); // expected-error{{redecl}}
};
};
+
+template<typename T>
+struct X1 {
+ static int *a;
+ void f(float *b) {
+ X1<T>::a = b; // expected-error{{incompatible}}
+ X1<T*>::a = b;
+ }
+};
diff --git a/test/SemaTemplate/default-arguments-cxx0x.cpp b/test/SemaTemplate/default-arguments-cxx0x.cpp
new file mode 100644
index 0000000..8d8833c
--- /dev/null
+++ b/test/SemaTemplate/default-arguments-cxx0x.cpp
@@ -0,0 +1,26 @@
+// RUN: clang-cc -fsyntax-only -std=c++0x -verify %s
+
+// Test default template arguments for function templates.
+template<typename T = int>
+void f0();
+
+template<typename T>
+void f0();
+
+void g0() {
+ f0(); // okay!
+}
+
+template<typename T, int N = T::value>
+int &f1(T);
+
+float &f1(...);
+
+struct HasValue {
+ static const int value = 17;
+};
+
+void g1() {
+ float &fr = f1(15);
+ int &ir = f1(HasValue());
+}
diff --git a/test/SemaTemplate/dependent-names.cpp b/test/SemaTemplate/dependent-names.cpp
index 95ee2d2..aef43cb 100644
--- a/test/SemaTemplate/dependent-names.cpp
+++ b/test/SemaTemplate/dependent-names.cpp
@@ -14,3 +14,73 @@ int a0[sizeof(X<int>::a) == sizeof(double) ? 1 : -1];
// PR4365.
template<class T> class Q;
template<class T> class R : Q<T> {T current;};
+
+
+namespace test0 {
+ template <class T> class Base {
+ void instance_foo();
+ static void static_foo();
+ class Inner {
+ void instance_foo();
+ static void static_foo();
+ };
+ };
+
+ template <class T> class Derived1 : Base<T> {
+ void test0() {
+ Base<T>::static_foo();
+ Base<T>::instance_foo();
+ }
+
+ void test1() {
+ Base<T>::Inner::static_foo();
+ Base<T>::Inner::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
+ }
+
+ static void test2() {
+ Base<T>::static_foo();
+ Base<T>::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
+ }
+
+ static void test3() {
+ Base<T>::Inner::static_foo();
+ Base<T>::Inner::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
+ }
+ };
+
+ template <class T> class Derived2 : Base<T>::Inner {
+ void test0() {
+ Base<T>::static_foo();
+ Base<T>::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
+ }
+
+ void test1() {
+ Base<T>::Inner::static_foo();
+ Base<T>::Inner::instance_foo();
+ }
+
+ static void test2() {
+ Base<T>::static_foo();
+ Base<T>::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
+ }
+
+ static void test3() {
+ Base<T>::Inner::static_foo();
+ Base<T>::Inner::instance_foo(); // expected-error {{call to non-static member function without an object argument}}
+ }
+ };
+
+ void test0() {
+ Derived1<int> d1;
+ d1.test0();
+ d1.test1(); // expected-note {{in instantiation of member function}}
+ d1.test2(); // expected-note {{in instantiation of member function}}
+ d1.test3(); // expected-note {{in instantiation of member function}}
+
+ Derived2<int> d2;
+ d2.test0(); // expected-note {{in instantiation of member function}}
+ d2.test1();
+ d2.test2(); // expected-note {{in instantiation of member function}}
+ d2.test3(); // expected-note {{in instantiation of member function}}
+ }
+}
diff --git a/test/SemaTemplate/dependent-sized_array.cpp b/test/SemaTemplate/dependent-sized_array.cpp
new file mode 100644
index 0000000..d221a4d
--- /dev/null
+++ b/test/SemaTemplate/dependent-sized_array.cpp
@@ -0,0 +1,17 @@
+// RUN: clang-cc -fsyntax-only -pedantic -verify %s
+
+template<int N>
+void f() {
+ int a[] = { 1, 2, 3, N };
+ unsigned numAs = sizeof(a) / sizeof(int);
+}
+
+template void f<17>();
+
+
+template<int N>
+void f1() {
+ int a0[] = {}; // expected-warning{{zero}}
+ int a1[] = { 1, 2, 3, N };
+ int a3[sizeof(a1)/sizeof(int) != 4? 1 : -1]; // expected-error{{negative}}
+}
diff --git a/test/SemaTemplate/destructor-template.cpp b/test/SemaTemplate/destructor-template.cpp
index a7c8d24..afe2cfc 100644
--- a/test/SemaTemplate/destructor-template.cpp
+++ b/test/SemaTemplate/destructor-template.cpp
@@ -9,4 +9,11 @@ template<typename A> class s0 {
};
+struct Incomplete;
+template<typename T>
+void destroy_me(T me) {
+ me.~T();
+}
+
+template void destroy_me(Incomplete*);
diff --git a/test/SemaTemplate/instantiate-function-1.cpp b/test/SemaTemplate/instantiate-function-1.cpp
index 2749ec2..a6c269f 100644
--- a/test/SemaTemplate/instantiate-function-1.cpp
+++ b/test/SemaTemplate/instantiate-function-1.cpp
@@ -106,9 +106,6 @@ template<typename T> struct Do0 {
void f(T t) {
do {
} while (t); // expected-error{{not contextually}}
-
- do {
- } while (T t2 = T());
}
};
diff --git a/test/SemaTemplate/instantiate-member-template.cpp b/test/SemaTemplate/instantiate-member-template.cpp
index 95556bc..04ced92 100644
--- a/test/SemaTemplate/instantiate-member-template.cpp
+++ b/test/SemaTemplate/instantiate-member-template.cpp
@@ -116,3 +116,18 @@ struct X2 {
X2<int&> x2a; // expected-note{{instantiation}}
X2<float> x2b; // expected-note{{instantiation}}
+
+namespace N0 {
+ template<typename T>
+ struct X0 { };
+
+ struct X1 {
+ template<typename T> void f(X0<T>& vals) { g(vals); }
+ template<typename T> void g(X0<T>& vals) { }
+ };
+
+ void test(X1 x1, X0<int> x0i, X0<long> x0l) {
+ x1.f(x0i);
+ x1.f(x0l);
+ }
+}
diff --git a/test/SemaTemplate/instantiate-method.cpp b/test/SemaTemplate/instantiate-method.cpp
index df1e1d9..2351d88 100644
--- a/test/SemaTemplate/instantiate-method.cpp
+++ b/test/SemaTemplate/instantiate-method.cpp
@@ -84,6 +84,8 @@ int *a(A0<int> &x0, A1<int> &x1) {
struct X0Base {
int &f();
+ int& g(int);
+ static double &g(double);
};
template<typename T>
@@ -92,9 +94,28 @@ struct X0 : X0Base {
template<typename U>
struct X1 : X0<U> {
- int &f2() { return X0Base::f(); }
+ 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}}
+ }
};
void test_X1(X1<int> x1i) {
int &ir = x1i.f2();
}
+
+template<typename U>
+struct X2 : X0Base, U {
+ int &f2() { return X0Base::f(); }
+};
+
+template<typename T>
+struct X3 {
+ void test(T x) {
+ double& d1 = X0Base::g(x);
+ }
+};
+
+
+template struct X3<double>;
diff --git a/test/SemaTemplate/instantiate-static-var.cpp b/test/SemaTemplate/instantiate-static-var.cpp
index 96fa34c..452fccf 100644
--- a/test/SemaTemplate/instantiate-static-var.cpp
+++ b/test/SemaTemplate/instantiate-static-var.cpp
@@ -1,5 +1,4 @@
// RUN: clang-cc -fsyntax-only -verify %s
-
template<typename T, T Divisor>
class X {
public:
@@ -38,3 +37,38 @@ void test() {
DefCon &DC = Z<DefCon>::value;
NoDefCon &NDC = Z<NoDefCon>::value; // expected-note{{instantiation}}
}
+
+// PR5609
+struct X1 {
+ ~X1(); // The errors won't be triggered without this dtor.
+};
+
+template <typename T>
+struct Y1 {
+ static char Helper(T);
+ static const int value = sizeof(Helper(T()));
+};
+
+struct X2 {
+ virtual ~X2();
+};
+
+namespace std {
+ class type_info { };
+}
+
+template <typename T>
+struct Y2 {
+ static T &Helper();
+ static const int value = sizeof(typeid(Helper()));
+};
+
+template <int>
+struct Z1 {};
+
+void Test() {
+ Z1<Y1<X1>::value> x;
+ int y[Y1<X1>::value];
+ Z1<Y2<X2>::value> x2;
+ int y2[Y2<X2>::value];
+}
diff --git a/test/SemaTemplate/instantiation-depth.cpp b/test/SemaTemplate/instantiation-depth.cpp
index 522c4e1..31abb40 100644
--- a/test/SemaTemplate/instantiation-depth.cpp
+++ b/test/SemaTemplate/instantiation-depth.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-cc -fsyntax-only -ftemplate-depth=5 -verify %s
+// RUN: clang-cc -fsyntax-only -ftemplate-depth 5 -verify %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}} \
diff --git a/test/SemaTemplate/nested-name-spec-template.cpp b/test/SemaTemplate/nested-name-spec-template.cpp
index e936640..436732a 100644
--- a/test/SemaTemplate/nested-name-spec-template.cpp
+++ b/test/SemaTemplate/nested-name-spec-template.cpp
@@ -1,4 +1,4 @@
-// RUN: clang-cc -fsyntax-only -verify -fms-extensions=0 %s
+// RUN: clang-cc -fsyntax-only -verify %s
namespace N {
namespace M {
diff --git a/test/SemaTemplate/overload-uneval.cpp b/test/SemaTemplate/overload-uneval.cpp
new file mode 100644
index 0000000..2e3bfed
--- /dev/null
+++ b/test/SemaTemplate/overload-uneval.cpp
@@ -0,0 +1,42 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+// Tests that overload resolution is treated as an unevaluated context.
+// PR5541
+struct Foo
+{
+ Foo *next;
+};
+
+template <typename>
+struct Bar
+{
+};
+
+
+template <typename T>
+class Wibble
+{
+ typedef Bar<T> B;
+
+ static inline B *concrete(Foo *node) {
+ int a[sizeof(T) ? -1 : -1];
+ return reinterpret_cast<B *>(node);
+ }
+
+public:
+ class It
+ {
+ Foo *i;
+
+ public:
+ inline operator B *() const { return concrete(i); }
+ inline bool operator!=(const It &o) const { return i !=
+o.i; }
+ };
+};
+
+void f() {
+ Wibble<void*>::It a, b;
+
+ a != b;
+}
diff --git a/test/SemaTemplate/qualified-id.cpp b/test/SemaTemplate/qualified-id.cpp
index 85efab2..a07f05c 100644
--- a/test/SemaTemplate/qualified-id.cpp
+++ b/test/SemaTemplate/qualified-id.cpp
@@ -7,3 +7,14 @@ namespace a {
namespace b {
template<typename T> void f0(a::C<T> &a0) { }
}
+
+
+namespace test1 {
+ int a = 0;
+ template <class T> class Base { };
+ template <class T> class Derived : public Base<T> {
+ int foo() {
+ return test1::a;
+ }
+ };
+}
diff --git a/test/SemaTemplate/temp_arg_nontype.cpp b/test/SemaTemplate/temp_arg_nontype.cpp
index bde92be..0c44651 100644
--- a/test/SemaTemplate/temp_arg_nontype.cpp
+++ b/test/SemaTemplate/temp_arg_nontype.cpp
@@ -151,3 +151,12 @@ namespace ns {
Baz<static_cast<ns::E>(0)> b2; // This neither.
}
+// PR5597
+template<int (*)(float)> struct X0 { };
+
+struct X1 {
+ static int pfunc(float);
+};
+void test_X0_X1() {
+ X0<X1::pfunc> x01;
+}
diff --git a/test/SemaTemplate/temp_explicit.cpp b/test/SemaTemplate/temp_explicit.cpp
index 9c824d6..ae409af 100644
--- a/test/SemaTemplate/temp_explicit.cpp
+++ b/test/SemaTemplate/temp_explicit.cpp
@@ -108,3 +108,20 @@ struct X6 {
};
template struct X6::Inner; // expected-error{{non-templated}}
+
+// PR5559
+template <typename T>
+struct Foo;
+
+template <>
+struct Foo<int> // expected-note{{header not required for explicitly-specialized}}
+{
+ template <typename U>
+ struct Bar
+ {};
+};
+
+template <> // expected-warning{{extraneous template parameter list}}
+template <>
+struct Foo<int>::Bar<void>
+{};
OpenPOWER on IntegriCloud