aboutsummaryrefslogtreecommitdiff
path: root/test/SemaTemplate/ackermann.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-06-05 00:53:49 +0000
committerDouglas Gregor <dgregor@apple.com>2009-06-05 00:53:49 +0000
commit199d99192fbcca9f043596c40ead4afab4999dba (patch)
tree14716988cdd0af1ae955782954af60f098390770 /test/SemaTemplate/ackermann.cpp
parent29b1d07a87a2038ae5b4128a0b534badd728707d (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72909 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaTemplate/ackermann.cpp')
-rw-r--r--test/SemaTemplate/ackermann.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/SemaTemplate/ackermann.cpp b/test/SemaTemplate/ackermann.cpp
new file mode 100644
index 0000000000..48fbbbb3cf
--- /dev/null
+++ b/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];