[compiler-rt] Add weak defs for .*contiguous_container.* functions (#120376)
[llvm-project.git] / clang / test / CXX / temp / temp.decls / temp.mem / p5.cpp
blob668941b4014197db9392c7a2787fc0d41c00af86
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
6 struct A {
7 template <class T> operator T*();
8 };
10 template <class T> A::operator T*() { return 0; }
11 template <> A::operator char*(){ return 0; } // specialization
12 template A::operator void*(); // explicit instantiation
14 int main() {
15 A a;
16 int *ip;
17 ip = a.operator int*();
20 // PR5742
21 namespace PR5742 {
22 template <class T> struct A { };
23 template <class T> struct B { };
25 struct S {
26 template <class T> operator T();
27 } s;
29 void f() {
30 s.operator A<A<int> >();
31 s.operator A<B<int> >();
32 s.operator A<B<A<int> > >();
36 // PR5762
37 class Foo {
38 public:
39 template <typename T> operator T();
41 template <typename T>
42 T As() {
43 return this->operator T();
46 template <typename T>
47 T As2() {
48 return operator T();
51 int AsInt() {
52 return this->operator int();
56 template float Foo::As();
57 template double Foo::As2();
59 // Partial ordering with conversion function templates.
60 struct X0 {
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 {
69 T x = T();
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*();
87 namespace PR14211 {
88 template <class U> struct X {
89 void foo(U){}
90 template <class T> void foo(T){}
92 template <class T> void bar(T){}
93 void bar(U){}
96 template void X<int>::foo(int);
97 template void X<int>::bar(int);