diff options
| author | Douglas Gregor <dgregor@apple.com> | 2009-06-26 18:27:22 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2009-06-26 18:27:22 +0000 |
| commit | cceb97559ed193c9c61927497be541154a0f86b7 (patch) | |
| tree | a85565f7b36de1cec44cf71f2dce6656abbb113c /clang/test | |
| parent | 88efd1fed3e5afd733055832c26f422971a8a351 (diff) | |
| download | bcm5719-llvm-cceb97559ed193c9c61927497be541154a0f86b7.tar.gz bcm5719-llvm-cceb97559ed193c9c61927497be541154a0f86b7.zip | |
Improve template argument deduction for reference parameters when
deducing template arguments from a function call. Plus, add a bunch of
tests.
llvm-svn: 74301
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p2.cpp | 31 | ||||
| -rw-r--r-- | clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp | 44 |
2 files changed, 75 insertions, 0 deletions
diff --git a/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p2.cpp b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p2.cpp new file mode 100644 index 00000000000..6f27d363689 --- /dev/null +++ b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p2.cpp @@ -0,0 +1,31 @@ +// RUN: clang-cc -fsyntax-only -verify %s +template<typename T> struct A { }; + +// bullet 1 +template<typename T> A<T> f0(T* ptr); + +void test_f0_bullet1() { + int arr0[6]; + A<int> a0 = f0(arr0); + const int arr1[] = { 1, 2, 3, 4, 5 }; + A<const int> a1 = f0(arr1); +} + +// bullet 2 +int g0(int, int); +float g1(float); + +void test_f0_bullet2() { + A<int(int, int)> a0 = f0(g0); + A<float(float)> a1 = f0(g1); +} + +// bullet 3 +struct X { }; +const X get_X(); + +template<typename T> A<T> f1(T); + +void test_f1_bullet3() { + A<X> a0 = f1(get_X()); +} diff --git a/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp new file mode 100644 index 00000000000..18023523a9b --- /dev/null +++ b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp @@ -0,0 +1,44 @@ +// RUN: clang-cc -fsyntax-only %s + +template<typename T> struct A { }; + +// Top-level cv-qualifiers of P's type are ignored for type deduction. +template<typename T> A<T> f0(const T); + +void test_f0(int i, const int ci) { + A<int> a0 = f0(i); + A<int> a1 = f0(ci); +} + +// If P is a reference type, the type referred to by P is used for type +// deduction. +template<typename T> A<T> f1(T&); + +void test_f1(int i, const int ci, volatile int vi) { + A<int> a0 = f1(i); + A<const int> a1 = f1(ci); + A<volatile int> a2 = f1(vi); +} + +template<typename T, unsigned N> struct B { }; +template<typename T, unsigned N> B<T, N> g0(T (&array)[N]); + +void test_g0() { + int array0[5]; + B<int, 5> b0 = g0(array0); + const int array1[] = { 1, 2, 3}; + B<const int, 3> b1 = g0(array1); +} + +// - If the original P is a reference type, the deduced A (i.e., the type +// referred to by the reference) can be more cv-qualified than the +// transformed A. +template<typename T> A<T> f2(const T&); + +void test_f2(int i, const int ci, volatile int vi) { + A<int> a0 = f2(i); + A<int> a1 = f2(ci); + A<volatile int> a2 = f2(vi); +} + +// FIXME: the next two bullets require a bit of effort.
\ No newline at end of file |

