summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaTemplate/function-template-specialization.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-09-24 23:14:47 +0000
committerDouglas Gregor <dgregor@apple.com>2009-09-24 23:14:47 +0000
commit3a923c2d379966dff3d0a709e42360ae8e402053 (patch)
treeadb6e64ae68d0be1fc6a532be78b5656dc8dd5c3 /clang/test/SemaTemplate/function-template-specialization.cpp
parentd6f9a2f90bd5e485871c5281904a907c02968bfa (diff)
downloadbcm5719-llvm-3a923c2d379966dff3d0a709e42360ae8e402053.tar.gz
bcm5719-llvm-3a923c2d379966dff3d0a709e42360ae8e402053.zip
WIP implementation of explicit function template specialization. This
first implementation recognizes when a function declaration is an explicit function template specialization (based on the presence of a template<> header), performs template argument deduction + ambiguity resolution to determine which template is being specialized, and hooks There are many caveats here: - We completely and totally drop any explicitly-specified template arguments on the floor - We don't diagnose any of the extra semantic things that we should diagnose. - I haven't looked to see that we're getting the right linkage for explicit specializations On a happy note, this silences a bunch of errors that show up in libstdc++'s <iostream>, although Clang still can't get through the entire header. llvm-svn: 82728
Diffstat (limited to 'clang/test/SemaTemplate/function-template-specialization.cpp')
-rw-r--r--clang/test/SemaTemplate/function-template-specialization.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/test/SemaTemplate/function-template-specialization.cpp b/clang/test/SemaTemplate/function-template-specialization.cpp
new file mode 100644
index 00000000000..5946d9b680b
--- /dev/null
+++ b/clang/test/SemaTemplate/function-template-specialization.cpp
@@ -0,0 +1,25 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+template<int N> void f0(int (&array)[N]);
+
+// Simple function template specialization (using overloading)
+template<> void f0(int (&array)[1]);
+
+void test_f0() {
+ int iarr1[1];
+ f0(iarr1);
+}
+
+// Function template specialization where there are no matches
+template<> void f0(char (&array)[1]); // expected-error{{no function template matches}}
+
+// Function template specialization that requires partial ordering
+template<typename T, int N> void f1(T (&array)[N]); // expected-note{{matches}}
+template<int N> void f1(int (&array)[N]); // expected-note{{matches}}
+
+template<> void f1(float (&array)[1]);
+template<> void f1(int (&array)[1]);
+
+// Function template specialization that results in an ambiguity
+template<typename T> void f1(T (&array)[17]); // expected-note{{matches}}
+template<> void f1(int (&array)[17]); // expected-error{{ambiguous}}
OpenPOWER on IntegriCloud