diff options
Diffstat (limited to 'test/SemaTemplate')
-rw-r--r-- | test/SemaTemplate/attributes.cpp | 22 | ||||
-rw-r--r-- | test/SemaTemplate/dependent-names.cpp | 21 | ||||
-rw-r--r-- | test/SemaTemplate/example-dynarray.cpp | 178 | ||||
-rw-r--r-- | test/SemaTemplate/local-member-templates.cpp | 76 | ||||
-rw-r--r-- | test/SemaTemplate/ms-function-specialization-class-scope.cpp | 1 | ||||
-rw-r--r-- | test/SemaTemplate/ms-lookup-template-base-classes.cpp | 26 | ||||
-rw-r--r-- | test/SemaTemplate/overload-candidates.cpp | 17 | ||||
-rw-r--r-- | test/SemaTemplate/temp_arg_nontype.cpp | 9 |
8 files changed, 169 insertions, 181 deletions
diff --git a/test/SemaTemplate/attributes.cpp b/test/SemaTemplate/attributes.cpp index 495f4a7..5a06a70 100644 --- a/test/SemaTemplate/attributes.cpp +++ b/test/SemaTemplate/attributes.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=gnu++11 -fsyntax-only -verify %s namespace attribute_aligned { template<int N> @@ -18,6 +18,26 @@ namespace attribute_aligned { check_alignment<2>::t c2; check_alignment<3>::t c3; // expected-note 2 {{in instantiation}} check_alignment<4>::t c4; + + template<unsigned Size, unsigned Align> + class my_aligned_storage + { + __attribute__((align(Align))) char storage[Size]; + }; + + template<typename T> + class C { + public: + C() { + static_assert(sizeof(t) == sizeof(T), "my_aligned_storage size wrong"); + static_assert(alignof(t) == alignof(T), "my_aligned_storage align wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}} + } + + private: + my_aligned_storage<sizeof(T), alignof(T)> t; + }; + + C<double> cd; } namespace PR9049 { diff --git a/test/SemaTemplate/dependent-names.cpp b/test/SemaTemplate/dependent-names.cpp index eb75e69..fa47ef5 100644 --- a/test/SemaTemplate/dependent-names.cpp +++ b/test/SemaTemplate/dependent-names.cpp @@ -264,7 +264,7 @@ namespace PR10053 { } namespace PR10187 { - namespace A { + namespace A1 { template<typename T> struct S { void f() { @@ -278,6 +278,25 @@ namespace PR10187 { } } + namespace A2 { + template<typename T> + struct S { + void f() { + for (auto &a : e) + __range(a); // expected-error {{undeclared identifier '__range'}} + } + T e[10]; + }; + void g() { + S<int>().f(); // expected-note {{here}} + } + struct X {}; + void __range(X); + void h() { + S<X>().f(); + } + } + namespace B { template<typename T> void g(); // expected-note {{not viable}} template<typename T> void f() { diff --git a/test/SemaTemplate/example-dynarray.cpp b/test/SemaTemplate/example-dynarray.cpp deleted file mode 100644 index 266d2d4..0000000 --- a/test/SemaTemplate/example-dynarray.cpp +++ /dev/null @@ -1,178 +0,0 @@ -// RUN: %clangxx -emit-llvm -c -o - %s -// XFAIL: hexagon -#include <stddef.h> -#include <stdlib.h> -#include <assert.h> - -// Placement new requires <new> to be included, but we don't support that yet. -void* operator new(size_t, void* ptr) throw() { - return ptr; -} -void operator delete(void*, void*) throw() { -} - -template<typename T> -class dynarray { -public: - dynarray() { Start = Last = End = 0; } - - dynarray(const dynarray &other) { - Start = (T*)malloc(sizeof(T) * other.size()); - Last = End = Start + other.size(); - - for (unsigned I = 0, N = other.size(); I != N; ++I) - new (Start + I) T(other[I]); - } - - ~dynarray() { - for (unsigned I = 0, N = size(); I != N; ++I) - Start[I].~T(); - - free(Start); - } - - dynarray &operator=(const dynarray &other) { - T* NewStart = (T*)malloc(sizeof(T) * other.size()); - - for (unsigned I = 0, N = other.size(); I != N; ++I) - new (NewStart + I) T(other[I]); - - for (unsigned I = 0, N = size(); I != N; ++I) - Start[I].~T(); - - free(Start); - Start = NewStart; - Last = End = NewStart + other.size(); - return *this; - } - - unsigned size() const { return Last - Start; } - unsigned capacity() const { return End - Start; } - - void push_back(const T& value); - - void pop_back() { - --Last; - Last->~T(); - } - - T& operator[](unsigned Idx) { - return Start[Idx]; - } - - const T& operator[](unsigned Idx) const { - return Start[Idx]; - } - - typedef T* iterator; - typedef const T* const_iterator; - - iterator begin() { return Start; } - const_iterator begin() const { return Start; } - - iterator end() { return Last; } - const_iterator end() const { return Last; } - - bool operator==(const dynarray &other) const { - if (size() != other.size()) - return false; - - for (unsigned I = 0, N = size(); I != N; ++I) - if ((*this)[I] != other[I]) - return false; - - return true; - } - - bool operator!=(const dynarray &other) const { - return !(*this == other); - } - -public: - T* Start, *Last, *End; -}; - -template<typename T> -void dynarray<T>::push_back(const T& value) { - if (Last == End) { - unsigned NewCapacity = capacity() * 2; - if (NewCapacity == 0) - NewCapacity = 4; - - T* NewStart = (T*)malloc(sizeof(T) * NewCapacity); - - unsigned Size = size(); - for (unsigned I = 0; I != Size; ++I) - new (NewStart + I) T(Start[I]); - - for (unsigned I = 0, N = size(); I != N; ++I) - Start[I].~T(); - free(Start); - - Start = NewStart; - Last = Start + Size; - End = Start + NewCapacity; - } - - new (Last) T(value); - ++Last; -} - -struct Point { - Point() { x = y = z = 0.0; } - Point(const Point& other) : x(other.x), y(other.y), z(other.z) { } - - float x, y, z; -}; - -int main() { - dynarray<int> di; - di.push_back(0); - di.push_back(1); - di.push_back(2); - di.push_back(3); - di.push_back(4); - assert(di.size() == 5); - for (dynarray<int>::iterator I = di.begin(), IEnd = di.end(); I != IEnd; ++I) - assert(*I == I - di.begin()); - - for (int I = 0, N = di.size(); I != N; ++I) - assert(di[I] == I); - - di.pop_back(); - assert(di.size() == 4); - di.push_back(4); - - dynarray<int> di2 = di; - assert(di2.size() == 5); - assert(di.begin() != di2.begin()); - for (dynarray<int>::iterator I = di2.begin(), IEnd = di2.end(); - I != IEnd; ++I) - assert(*I == I - di2.begin()); - - dynarray<int> di3(di); - assert(di3.size() == 5); - assert(di.begin() != di3.begin()); - for (dynarray<int>::iterator I = di3.begin(), IEnd = di3.end(); - I != IEnd; ++I) - assert(*I == I - di3.begin()); - - dynarray<int> di4; - assert(di4.size() == 0); - di4 = di; - assert(di4.size() == 5); - assert(di.begin() != di4.begin()); - for (dynarray<int>::iterator I = di4.begin(), IEnd = di4.end(); - I != IEnd; ++I) - assert(*I == I - di4.begin()); - - assert(di4 == di); - di4[3] = 17; - assert(di4 != di); - - dynarray<Point> dp; - dp.push_back(Point()); - assert(dp.size() == 1); - - return 0; -} diff --git a/test/SemaTemplate/local-member-templates.cpp b/test/SemaTemplate/local-member-templates.cpp new file mode 100644 index 0000000..3cdf5df --- /dev/null +++ b/test/SemaTemplate/local-member-templates.cpp @@ -0,0 +1,76 @@ +// RUN: %clang_cc1 -std=c++1y -verify %s +// RUN: %clang_cc1 -std=c++1y -verify %s -fdelayed-template-parsing + +namespace nested_local_templates_1 { + +template <class T> struct Outer { + template <class U> int outer_mem(T t, U u) { + struct Inner { + template <class V> int inner_mem(T t, U u, V v) { + struct InnerInner { + template <class W> int inner_inner_mem(W w, T t, U u, V v) { + return 0; + } + }; + InnerInner().inner_inner_mem("abc", t, u, v); + return 0; + } + }; + Inner i; + i.inner_mem(t, u, 3.14); + return 0; + } + + template <class U> int outer_mem(T t, U *u); +}; + +template int Outer<int>::outer_mem(int, char); + +template <class T> template <class U> int Outer<T>::outer_mem(T t, U *u) { + struct Inner { + template <class V> + int inner_mem(T t, U u, V v) { //expected-note{{candidate function}} + struct InnerInner { + template <class W> int inner_inner_mem(W w, T t, U u, V v) { return 0; } + }; + InnerInner().inner_inner_mem("abc", t, u, v); + return 0; + } + }; + Inner i; + i.inner_mem(t, U{}, i); + i.inner_mem(t, u, 3.14); //expected-error{{no matching member function for call to 'inner}} + return 0; +} + +template int Outer<int>::outer_mem(int, char *); //expected-note{{in instantiation of function}} + +} // end ns + +namespace nested_local_templates_2 { + +template <class T> struct Outer { + template <class U> void outer_mem(T t, U u) { + struct Inner { + template <class V> struct InnerTemplateClass { + template <class W> + void itc_mem(T t, U u, V v, W w) { //expected-note{{candidate function}} + struct InnerInnerInner { + template <class X> void iii_mem(X x) {} + }; + InnerInnerInner i; + i.iii_mem("abc"); + } + }; + }; + Inner i; + typename Inner::template InnerTemplateClass<Inner> ii; + ii.itc_mem(t, u, i, "jim"); + ii.itc_mem(t, u, 0, "abd"); //expected-error{{no matching member function}} + } +}; + +template void +Outer<int>::outer_mem(int, char); //expected-note{{in instantiation of}} + +} diff --git a/test/SemaTemplate/ms-function-specialization-class-scope.cpp b/test/SemaTemplate/ms-function-specialization-class-scope.cpp index 131922b..9efb02c 100644 --- a/test/SemaTemplate/ms-function-specialization-class-scope.cpp +++ b/test/SemaTemplate/ms-function-specialization-class-scope.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s +// RUN: %clang_cc1 -fms-extensions -fdelayed-template-parsing -fsyntax-only -verify %s class A { diff --git a/test/SemaTemplate/ms-lookup-template-base-classes.cpp b/test/SemaTemplate/ms-lookup-template-base-classes.cpp index 8f80cb5..cb1a7f5 100644 --- a/test/SemaTemplate/ms-lookup-template-base-classes.cpp +++ b/test/SemaTemplate/ms-lookup-template-base-classes.cpp @@ -8,7 +8,6 @@ public: void g();// expected-note {{must qualify identifier to find this declaration in dependent base class}} }; - template <class T> class B : public A<T> { public: @@ -28,6 +27,31 @@ void test() b.z(3); } +struct A2 { + template<class T> void f(T) { + XX; //expected-error {{use of undeclared identifier 'XX'}} + A2::XX; //expected-error {{no member named 'XX' in 'A2'}} + } +}; +template void A2::f(int); + +template<class T0> +struct A3 { + template<class T1> void f(T1) { + XX; //expected-error {{use of undeclared identifier 'XX'}} + } +}; +template void A3<int>::f(int); + +template<class T0> +struct A4 { + void f(char) { + XX; //expected-error {{use of undeclared identifier 'XX'}} + } +}; +template class A4<int>; + + namespace lookup_dependent_bases_id_expr { template<class T> class A { diff --git a/test/SemaTemplate/overload-candidates.cpp b/test/SemaTemplate/overload-candidates.cpp index dc6d2a5..ad65397 100644 --- a/test/SemaTemplate/overload-candidates.cpp +++ b/test/SemaTemplate/overload-candidates.cpp @@ -62,3 +62,20 @@ template<typename T> struct NonTemplateFunction { typename boost::enable_if<sizeof(T) == 4, int>::type f(); // expected-error{{no type named 'type' in 'boost::enable_if<false, int>'; 'enable_if' cannot be used to disable this declaration}} }; NonTemplateFunction<char> NTFC; // expected-note{{here}} + +namespace NS1 { + template <class A> + class array {}; +} + +namespace NS2 { + template <class A> + class array {}; +} + +template <class A> +void foo(NS2::array<A>); // expected-note{{candidate template ignored: could not match 'NS2::array' against 'NS1::array'}} + +void test() { + foo(NS1::array<int>()); // expected-error{{no matching function for call to 'foo'}} +} diff --git a/test/SemaTemplate/temp_arg_nontype.cpp b/test/SemaTemplate/temp_arg_nontype.cpp index 210b5e4..2450952 100644 --- a/test/SemaTemplate/temp_arg_nontype.cpp +++ b/test/SemaTemplate/temp_arg_nontype.cpp @@ -337,3 +337,12 @@ namespace rdar13000548 { } } + +namespace rdar13806270 { + template <unsigned N> class X { }; + const unsigned value = 32; + struct Y { + X<value + 1> x; + }; + void foo() {} +} |