From: Douglas Gregor Date: Mon, 11 Jan 2010 19:52:23 +0000 (+0000) Subject: Test case for naming of conversion function template specializations X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9791bdc9b67435376f0b65686b627f5b3c6d1869;p=clang Test case for naming of conversion function template specializations git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93177 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/CXX/temp/temp.decls/temp.mem/p5.cpp b/test/CXX/temp/temp.decls/temp.mem/p5.cpp new file mode 100644 index 0000000000..098ffa4dec --- /dev/null +++ b/test/CXX/temp/temp.decls/temp.mem/p5.cpp @@ -0,0 +1,78 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +struct A { + template operator T*(); +}; + +template A::operator T*() { return 0; } +template <> A::operator char*(){ return 0; } // specialization +template A::operator void*(); // explicit instantiation + +int main() { + A a; + int *ip; + ip = a.operator int*(); +} + +// PR5742 +namespace PR5742 { + template struct A { }; + template struct B { }; + + struct S { + template operator T(); + } s; + + void f() { + s.operator A >(); + s.operator A >(); + s.operator A > >(); + } +} + +// PR5762 +class Foo { + public: + template operator T(); + + template + T As() { + return this->operator T(); + } + + template + T As2() { + return operator T(); + } + + int AsInt() { + return this->operator int(); + } +}; + +template float Foo::As(); +template double Foo::As2(); + +// Partial ordering with conversion function templates. +struct X0 { + template operator T*() { + T x; + x = 17; // expected-error{{read-only variable is not assignable}} + } + + template operator T*() const; // expected-note{{explicit instantiation refers here}} + + template operator const T*() const { + T x = T(); + return x; // expected-error{{cannot initialize return object of type 'char const *' with an lvalue of type 'char'}} + } +}; + +template X0::operator const char*() const; // expected-note{{'X0::operator char const *' requested here}} +template X0::operator const int*(); // expected-note{{'X0::operator int const *' requested here}} +template X0::operator float*() const; // expected-error{{explicit instantiation of undefined function template}} + +void test_X0(X0 x0, const X0 &x0c) { + x0.operator const int*(); + x0.operator float *(); + x0c.operator const char*(); +}