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). --- .../function-template-specialization.cpp | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 clang/test/SemaTemplate/function-template-specialization.cpp (limited to 'clang/test/SemaTemplate/function-template-specialization.cpp') diff --git a/clang/test/SemaTemplate/function-template-specialization.cpp b/clang/test/SemaTemplate/function-template-specialization.cpp new file mode 100644 index 0000000..a0d41b2 --- /dev/null +++ b/clang/test/SemaTemplate/function-template-specialization.cpp @@ -0,0 +1,48 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +template 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}} +template<> void f0<2>(int (&array)[2]) { } + +// Function template specialization that requires partial ordering +template void f1(T (&array)[N]); // expected-note{{matches}} +template 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 void f1(T (&array)[17]); // expected-note{{matches}} +template<> void f1(int (&array)[17]); // expected-error{{ambiguous}} + +// Resolving that ambiguity with explicitly-specified template arguments. +template void f2(double (&array)[N]); +template void f2(T (&array)[42]); + +template<> void f2(double (&array)[42]); +template<> void f2<42>(double (&array)[42]); + +void f2<25>(double (&array)[25]); // expected-error{{specialization}} + +// PR5833 +namespace PR5833 { + template bool f0(T &t1); + template <> bool f0(float &t1); +} +template <> bool PR5833::f0(float &t1) {} + +// PR8295 +namespace PR8295 { + template void f(T t) {} + template void f(T* t) {} // expected-error{{function template partial specialization is not allowed}} +} -- cgit v1.2.3