diff options
author | Zancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au> | 2012-09-24 09:58:17 +1000 |
---|---|---|
committer | Zancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au> | 2012-09-24 09:58:17 +1000 |
commit | 222e2a7620e6520ffaf4fc4e69d79c18da31542e (patch) | |
tree | 7bfbc05bfa3b41c8f9d2e56d53a0bc3e310df239 /clang/test/SemaTemplate/instantiate-init.cpp | |
parent | 3d206f03985b50beacae843d880bccdc91a9f424 (diff) |
Add the clang library to the repo (with some of my changes, too).
Diffstat (limited to 'clang/test/SemaTemplate/instantiate-init.cpp')
-rw-r--r-- | clang/test/SemaTemplate/instantiate-init.cpp | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/clang/test/SemaTemplate/instantiate-init.cpp b/clang/test/SemaTemplate/instantiate-init.cpp new file mode 100644 index 0000000..f0ca9a5 --- /dev/null +++ b/clang/test/SemaTemplate/instantiate-init.cpp @@ -0,0 +1,109 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +struct X0 { // expected-note 4{{candidate}} + X0(int*, float*); // expected-note 4{{candidate}} +}; + +template<typename T, typename U> +X0 f0(T t, U u) { + X0 x0(t, u); // expected-error{{no matching}} + return X0(t, u); // expected-error{{no matching}} +} + +void test_f0(int *ip, float *fp, double *dp) { + f0(ip, fp); + f0(ip, dp); // expected-note{{instantiation}} +} + +template<typename Ret, typename T, typename U> +Ret f1(Ret *retty, T t, U u) { + Ret r0(t, u); // expected-error{{no matching}} + return Ret(t, u); // expected-error{{no matching}} +} + +void test_f1(X0 *x0, int *ip, float *fp, double *dp) { + f1(x0, ip, fp); + f1(x0, ip, dp); // expected-note{{instantiation}} +} + +namespace PR6457 { + template <typename T> struct X { explicit X(T* p = 0) { }; }; + template <typename T> struct Y { Y(int, const T& x); }; + struct A { }; + template <typename T> + struct B { + B() : y(0, X<A>()) { } + Y<X<A> > y; + }; + B<int> b; +} + +namespace PR6657 { + struct X + { + X (int, int) { } + }; + + template <typename> + void f0() + { + X x = X(0, 0); + } + + void f1() + { + f0<int>(); + } +} + +// Instantiate out-of-line definitions of static data members which complete +// types through an initializer even when the only use of the member that would +// cause instantiation is in an unevaluated context, but one requiring its +// complete type. +namespace PR10001 { + template <typename T> struct S { + static const int arr[]; + static const int x; + static int f(); + }; + + template <typename T> const int S<T>::arr[] = { 1, 2, 3 }; + template <typename T> const int S<T>::x = sizeof(arr) / sizeof(arr[0]); + template <typename T> int S<T>::f() { return x; } + + int x = S<int>::f(); +} + +namespace PR7985 { + template<int N> struct integral_c { }; + + template <typename T, int N> + integral_c<N> array_lengthof(T (&x)[N]) { return integral_c<N>(); } // expected-note 2{{candidate template ignored: failed template argument deduction}} + + template<typename T> + struct Data { + T x; + }; + + template<typename T> + struct Description { + static const Data<T> data[]; + }; + + template<typename T> + const Data<T> Description<T>::data[] = {{ 1 }}; // expected-error{{cannot initialize a member subobject of type 'int *' with an rvalue of type 'int'}} + + template<> + Data<float*> Description<float*>::data[]; + + void test() { + integral_c<1> ic1 = array_lengthof(Description<int>::data); + (void)sizeof(array_lengthof(Description<float>::data)); + + sizeof(array_lengthof( // expected-error{{no matching function for call to 'array_lengthof'}} + Description<int*>::data // expected-note{{in instantiation of static data member 'PR7985::Description<int *>::data' requested here}} + )); + + array_lengthof(Description<float*>::data); // expected-error{{no matching function for call to 'array_lengthof'}} + } +} |