From 222e2a7620e6520ffaf4fc4e69d79c18da31542e Mon Sep 17 00:00:00 2001 From: "Zancanaro; Carlo" Date: Mon, 24 Sep 2012 09:58:17 +1000 Subject: Add the clang library to the repo (with some of my changes, too). --- clang/test/SemaTemplate/deduction.cpp | 164 ++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 clang/test/SemaTemplate/deduction.cpp (limited to 'clang/test/SemaTemplate/deduction.cpp') diff --git a/clang/test/SemaTemplate/deduction.cpp b/clang/test/SemaTemplate/deduction.cpp new file mode 100644 index 0000000..aecb5ee --- /dev/null +++ b/clang/test/SemaTemplate/deduction.cpp @@ -0,0 +1,164 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// Template argument deduction with template template parameters. +template class A> +struct X0 { + static const unsigned value = 0; +}; + +template class A> +struct X0 { + static const unsigned value = 1; +}; + +template struct X0i; +template struct X0l; +int array_x0a[X0::value == 0? 1 : -1]; +int array_x0b[X0::value == 1? 1 : -1]; + +template +struct is_same { + static const bool value = false; +}; + +template +struct is_same { + static const bool value = true; +}; + +template struct allocator { }; +template > struct vector {}; + +// Fun with meta-lambdas! +struct _1 {}; +struct _2 {}; + +// Replaces all occurrences of _1 with Arg1 and _2 with Arg2 in T. +template +struct Replace { + typedef T type; +}; + +// Replacement of the whole type. +template +struct Replace<_1, Arg1, Arg2> { + typedef Arg1 type; +}; + +template +struct Replace<_2, Arg1, Arg2> { + typedef Arg2 type; +}; + +// Replacement through cv-qualifiers +template +struct Replace { + typedef typename Replace::type const type; +}; + +// Replacement of templates +template class TT, typename T1, typename Arg1, typename Arg2> +struct Replace, Arg1, Arg2> { + typedef TT::type> type; +}; + +template class TT, typename T1, typename T2, + typename Arg1, typename Arg2> +struct Replace, Arg1, Arg2> { + typedef TT::type, + typename Replace::type> type; +}; + +// Just for kicks... +template class TT, typename T1, + typename Arg1, typename Arg2> +struct Replace, Arg1, Arg2> { + typedef TT::type, Arg2> type; +}; + +int array0[is_same::type, int>::value? 1 : -1]; +int array1[is_same::type, const int>::value? 1 : -1]; +int array2[is_same, int, float>::type, vector >::value? 1 : -1]; +int array3[is_same, int, float>::type, vector >::value? 1 : -1]; +int array4[is_same, double, float>::type, vector >::value? 1 : -1]; + +// PR5911 +template void f(const T (&a)[N]); +int iarr[] = { 1 }; +void test_PR5911() { f(iarr); } + +// Must not examine base classes of incomplete type during template argument +// deduction. +namespace PR6257 { + template struct X { + template X(const X& u); + }; + struct A; + void f(A& a); + void f(const X& a); + void test(A& a) { (void)f(a); } +} + +// PR7463 +namespace PR7463 { + const int f (); + template void g (T_&); // expected-note{{T_ = int}} + void h (void) { g(f()); } // expected-error{{no matching function for call}} +} + +namespace test0 { + template void make(const T *(*fn)()); // expected-note {{candidate template ignored: can't deduce a type for 'T' which would make 'const T' equal 'char'}} + char *char_maker(); + void test() { + make(char_maker); // expected-error {{no matching function for call to 'make'}} + } +} + +namespace test1 { + template void foo(const T a[3][3]); + void test() { + int a[3][3]; + foo(a); + } +} + +// PR7708 +namespace test2 { + template struct Const { typedef void const type; }; + + template void f(T, typename Const::type*); + template void f(T, void const *); + + void test() { + void *p = 0; + f(0, p); + } +} + +// rdar://problem/8537391 +namespace test3 { + struct Foo { + template static inline void foo(); + }; + + class Bar { + template static inline void wobble(T ch); + + public: + static void madness() { + Foo::foo >(); + } + }; +} + +// Verify that we can deduce enum-typed arguments correctly. +namespace test14 { + enum E { E0, E1 }; + template struct A {}; + template void foo(const A &a) {} + + void test() { + A a; + foo(a); + } +} -- cgit v1.2.3