diff options
| author | Douglas Gregor <dgregor@apple.com> | 2009-06-05 00:53:49 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2009-06-05 00:53:49 +0000 |
| commit | b7ae10f764baceba4c890fa44ef14b71822ebd85 (patch) | |
| tree | fbde148b9fda7e4174e23c84d8f5fdd5a1930ae9 /clang/test | |
| parent | 8df7462f698becbef4fc0e7459c065810c38175a (diff) | |
| download | bcm5719-llvm-b7ae10f764baceba4c890fa44ef14b71822ebd85.tar.gz bcm5719-llvm-b7ae10f764baceba4c890fa44ef14b71822ebd85.zip | |
Several improvements to template argument deduction:
- Once we have deduced template arguments for a class template partial
specialization, we use exactly those template arguments for instantiating
the definition of the class template partial specialization.
- Added template argument deduction for non-type template parameters.
- Added template argument deduction for dependently-sized array types.
With these changes, we can now implement, e.g., the remove_reference
type trait. Also, Daniel's Ackermann template metaprogram now compiles
properly.
llvm-svn: 72909
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/SemaTemplate/ackermann.cpp | 37 | ||||
| -rw-r--r-- | clang/test/SemaTemplate/temp_class_spec.cpp | 23 |
2 files changed, 60 insertions, 0 deletions
diff --git a/clang/test/SemaTemplate/ackermann.cpp b/clang/test/SemaTemplate/ackermann.cpp new file mode 100644 index 00000000000..48fbbbb3cf1 --- /dev/null +++ b/clang/test/SemaTemplate/ackermann.cpp @@ -0,0 +1,37 @@ +// RUN: clang-cc -fsyntax-only -ftemplate-depth=1000 -verify %s + +// template<unsigned M, unsigned N> +// struct Ackermann { +// enum { +// value = M ? (N ? Ackermann<M-1, Ackermann<M-1, N-1> >::value +// : Ackermann<M-1, 1>::value) +// : N + 1 +// }; +// }; + +template<unsigned M, unsigned N> +struct Ackermann { + enum { + value = Ackermann<M-1, Ackermann<M, N-1>::value >::value + }; +}; + +template<unsigned M> struct Ackermann<M, 0> { + enum { + value = Ackermann<M-1, 1>::value + }; +}; + +template<unsigned N> struct Ackermann<0, N> { + enum { + value = N + 1 + }; +}; + +template<> struct Ackermann<0, 0> { + enum { + value = 1 + }; +}; + +int g0[Ackermann<3, 8>::value == 2045 ? 1 : -1]; diff --git a/clang/test/SemaTemplate/temp_class_spec.cpp b/clang/test/SemaTemplate/temp_class_spec.cpp index d516f01d7fd..8cb46cf98f8 100644 --- a/clang/test/SemaTemplate/temp_class_spec.cpp +++ b/clang/test/SemaTemplate/temp_class_spec.cpp @@ -51,6 +51,19 @@ int is_same2[is_same<const int, int>::value? -1 : 1]; int is_same3[is_same<int_ptr, int>::value? -1 : 1]; template<typename T> +struct remove_reference { + typedef T type; +}; + +template<typename T> +struct remove_reference<T&> { + typedef T type; +}; + +int remove_ref0[is_same<remove_reference<int>::type, int>::value? 1 : -1]; +int remove_ref1[is_same<remove_reference<int&>::type, int>::value? 1 : -1]; + +template<typename T> struct is_incomplete_array { static const bool value = false; }; @@ -79,3 +92,13 @@ int array_with_4_elements0[is_array_with_4_elements<int[]>::value ? -1 : 1]; int array_with_4_elements1[is_array_with_4_elements<int[1]>::value ? -1 : 1]; int array_with_4_elements2[is_array_with_4_elements<int[4]>::value ? 1 : -1]; int array_with_4_elements3[is_array_with_4_elements<int[4][2]>::value ? 1 : -1]; + +template<typename T> +struct get_array_size; + +template<typename T, unsigned N> +struct get_array_size<T[N]> { + static const unsigned value = N; +}; + +int array_size0[get_array_size<int[12]>::value == 12? 1 : -1]; |

