p5.cpp revision c6daf0b29d6c48a99cb1ad707973a7e6dfcafd58
1// RUN: %clang_cc1 -fsyntax-only -verify %s
2struct A {
3  template <class T> operator T*();
4};
5
6template <class T> A::operator T*() { return 0; }
7template <> A::operator char*(){ return 0; } // specialization
8template A::operator void*(); // explicit instantiation
9
10int main() {
11  A a;
12  int *ip;
13  ip = a.operator int*();
14}
15
16// PR5742
17namespace PR5742 {
18  template <class T> struct A { };
19  template <class T> struct B { };
20
21  struct S {
22    template <class T> operator T();
23  } s;
24
25  void f() {
26    s.operator A<A<int> >();
27    s.operator A<B<int> >();
28    s.operator A<B<A<int> > >();
29  }
30}
31
32// PR5762
33class Foo {
34 public:
35  template <typename T> operator T();
36
37  template <typename T>
38  T As() {
39    return this->operator T();
40  }
41
42  template <typename T>
43  T As2() {
44    return operator T();
45  }
46
47  int AsInt() {
48    return this->operator int();
49  }
50};
51
52template float Foo::As();
53template double Foo::As2();
54
55// Partial ordering with conversion function templates.
56struct X0 {
57  template<typename T> operator T*() {
58    T x = 1;
59    x = 17; // expected-error{{read-only variable is not assignable}}
60  }
61
62  template<typename T> operator T*() const; // expected-note{{explicit instantiation refers here}}
63
64  template<typename T> operator const T*() const {
65    T x = T();
66    return x; // expected-error{{cannot initialize return object of type 'const char *' with an lvalue of type 'char'}}
67  }
68};
69
70template X0::operator const char*() const; // expected-note{{'X0::operator const char *<char>' requested here}}
71template X0::operator const int*(); // expected-note{{'X0::operator const int *<const int>' requested here}}
72template X0::operator float*() const; // expected-error{{explicit instantiation of undefined function template}}
73
74void test_X0(X0 x0, const X0 &x0c) {
75  x0.operator const int*();
76  x0.operator float *();
77  x0c.operator const char*();
78}
79