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