xref: /aosp_15_r20/external/clang/test/CXX/special/class.copy/p33-0x.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++11 -fsyntax-only -verify %s
2*67e74705SXin Li class X {
3*67e74705SXin Li   X(const X&);
4*67e74705SXin Li 
5*67e74705SXin Li public:
6*67e74705SXin Li   X();
7*67e74705SXin Li   X(X&&);
8*67e74705SXin Li };
9*67e74705SXin Li 
return_by_move(int i,X x)10*67e74705SXin Li X return_by_move(int i, X x) {
11*67e74705SXin Li   X x2;
12*67e74705SXin Li   if (i == 0)
13*67e74705SXin Li     return x;
14*67e74705SXin Li   else if (i == 1)
15*67e74705SXin Li     return x2;
16*67e74705SXin Li   else
17*67e74705SXin Li     return x;
18*67e74705SXin Li }
19*67e74705SXin Li 
throw_move_only(X x)20*67e74705SXin Li void throw_move_only(X x) {
21*67e74705SXin Li   X x2;
22*67e74705SXin Li   throw x;
23*67e74705SXin Li   throw x2;
24*67e74705SXin Li }
25*67e74705SXin Li 
26*67e74705SXin Li namespace PR10142 {
27*67e74705SXin Li   struct X {
28*67e74705SXin Li     X();
29*67e74705SXin Li     X(X&&);
30*67e74705SXin Li     X(const X&) = delete; // expected-note 2{{'X' has been explicitly marked deleted here}}
31*67e74705SXin Li   };
32*67e74705SXin Li 
f(int i)33*67e74705SXin Li   void f(int i) {
34*67e74705SXin Li     X x;
35*67e74705SXin Li     try {
36*67e74705SXin Li       X x2;
37*67e74705SXin Li       if (i)
38*67e74705SXin Li         throw x2; // okay
39*67e74705SXin Li       throw x; // expected-error{{call to deleted constructor of 'PR10142::X'}}
40*67e74705SXin Li     } catch (...) {
41*67e74705SXin Li     }
42*67e74705SXin Li   }
43*67e74705SXin Li 
44*67e74705SXin Li   template<typename T>
f2(int i)45*67e74705SXin Li   void f2(int i) {
46*67e74705SXin Li     T x;
47*67e74705SXin Li     try {
48*67e74705SXin Li       T x2;
49*67e74705SXin Li       if (i)
50*67e74705SXin Li         throw x2; // okay
51*67e74705SXin Li       throw x; // expected-error{{call to deleted constructor of 'PR10142::X'}}
52*67e74705SXin Li     } catch (...) {
53*67e74705SXin Li     }
54*67e74705SXin Li   }
55*67e74705SXin Li 
56*67e74705SXin Li   template void f2<X>(int); // expected-note{{in instantiation of function template specialization 'PR10142::f2<PR10142::X>' requested here}}
57*67e74705SXin Li }
58