xref: /llvm-project/clang/test/CXX/special/class.copy/p3-cxx11.cpp (revision ba15d186e5cef2620d562c6c9d9a6d570382cd0a)
1*ba15d186SMark de Wever // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++23 -fsyntax-only -verify %s
218192228SMatheus Izvekov // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++20 -fsyntax-only -verify %s
318192228SMatheus Izvekov // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++11 -fsyntax-only -verify %s
418192228SMatheus Izvekov class X {
518192228SMatheus Izvekov   X(const X&);
618192228SMatheus Izvekov 
718192228SMatheus Izvekov public:
818192228SMatheus Izvekov   X();
918192228SMatheus Izvekov   X(X&&);
1018192228SMatheus Izvekov };
1118192228SMatheus Izvekov 
return_by_move(int i,X x)1218192228SMatheus Izvekov X return_by_move(int i, X x) {
1318192228SMatheus Izvekov   X x2;
1418192228SMatheus Izvekov   if (i == 0)
1518192228SMatheus Izvekov     return x;
1618192228SMatheus Izvekov   else if (i == 1)
1718192228SMatheus Izvekov     return x2;
1818192228SMatheus Izvekov   else
1918192228SMatheus Izvekov     return x;
2018192228SMatheus Izvekov }
2118192228SMatheus Izvekov 
throw_move_only(X x)2218192228SMatheus Izvekov void throw_move_only(X x) {
2318192228SMatheus Izvekov   X x2;
2418192228SMatheus Izvekov   throw x;
2518192228SMatheus Izvekov   throw x2;
2618192228SMatheus Izvekov }
2718192228SMatheus Izvekov 
2818192228SMatheus Izvekov namespace PR10142 {
2918192228SMatheus Izvekov   struct X {
3018192228SMatheus Izvekov     X();
3118192228SMatheus Izvekov     X(X&&);
3218192228SMatheus Izvekov     X(const X&) = delete; // expected-note 2{{'X' has been explicitly marked deleted here}}
3318192228SMatheus Izvekov   };
3418192228SMatheus Izvekov 
f(int i)3518192228SMatheus Izvekov   void f(int i) {
3618192228SMatheus Izvekov     X x;
3718192228SMatheus Izvekov     try {
3818192228SMatheus Izvekov       X x2;
3918192228SMatheus Izvekov       if (i)
4018192228SMatheus Izvekov         throw x2; // okay
4115f3cd6bSMatheus Izvekov       throw x; // expected-error{{call to deleted constructor of 'X'}}
4218192228SMatheus Izvekov     } catch (...) {
4318192228SMatheus Izvekov     }
4418192228SMatheus Izvekov   }
4518192228SMatheus Izvekov 
4618192228SMatheus Izvekov   template<typename T>
f2(int i)4718192228SMatheus Izvekov   void f2(int i) {
4818192228SMatheus Izvekov     T x;
4918192228SMatheus Izvekov     try {
5018192228SMatheus Izvekov       T x2;
5118192228SMatheus Izvekov       if (i)
5218192228SMatheus Izvekov         throw x2; // okay
5318192228SMatheus Izvekov       throw x; // expected-error{{call to deleted constructor of 'PR10142::X'}}
5418192228SMatheus Izvekov     } catch (...) {
5518192228SMatheus Izvekov     }
5618192228SMatheus Izvekov   }
5718192228SMatheus Izvekov 
5818192228SMatheus Izvekov   template void f2<X>(int); // expected-note{{in instantiation of function template specialization 'PR10142::f2<PR10142::X>' requested here}}
5918192228SMatheus Izvekov }
60