1 // RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify=expected,cxx23 %s
2 // RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx98_20 %s
3 // RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify=expected,cxx98_20 %s
4 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx98_20 %s
7 template <class T
> operator T
*();
10 template <class T
> A::operator T
*() { return 0; }
11 template <> A::operator char*(){ return 0; } // specialization
12 template A::operator void*(); // explicit instantiation
17 ip
= a
.operator int*();
22 template <class T
> struct A
{ };
23 template <class T
> struct B
{ };
26 template <class T
> operator T();
30 s
.operator A
<A
<int> >();
31 s
.operator A
<B
<int> >();
32 s
.operator A
<B
<A
<int> > >();
39 template <typename T
> operator T();
43 return this->operator T();
52 return this->operator int();
56 template float Foo::As();
57 template double Foo::As2();
59 // Partial ordering with conversion function templates.
61 template<typename T
> operator T
*() {
62 T x
= 1; // expected-note{{variable 'x' declared const here}}
63 x
= 17; // expected-error{{cannot assign to variable 'x' with const-qualified type 'const int'}}
66 template<typename T
> operator T
*() const; // expected-note{{explicit instantiation refers here}}
68 template<typename T
> operator const T
*() const {
70 return x
; // cxx98_20-error{{cannot initialize return object of type 'const char *' with an lvalue of type 'char'}} \
71 // cxx98_20-error{{cannot initialize return object of type 'const int *' with an lvalue of type 'int'}} \
72 // cxx23-error{{cannot initialize return object of type 'const char *' with an rvalue of type 'char'}} \
73 // cxx23-error{{cannot initialize return object of type 'const int *' with an rvalue of type 'int'}}
77 template X0::operator const char*() const; // expected-note{{'X0::operator const char *<char>' requested here}}
78 template X0::operator const int*(); // expected-note{{'X0::operator const int *<const int>' requested here}}
79 template X0::operator float*() const; // expected-error{{explicit instantiation of undefined function template 'operator type-parameter-0-0 *'}}
81 void test_X0(X0 x0
, const X0
&x0c
) {
82 x0
.operator const int*(); // expected-note{{in instantiation of function template specialization}}
83 x0
.operator float *();
84 x0c
.operator const char*();
88 template <class U
> struct X
{
90 template <class T
> void foo(T
){}
92 template <class T
> void bar(T
){}
96 template void X
<int>::foo(int);
97 template void X
<int>::bar(int);