1 // { dg-do run { target c++11 } } 2 3 // 2011-04-27 Paolo Carlini <paolo.carlini@oracle.com> 4 // 5 // Copyright (C) 2011-2018 Free Software Foundation, Inc. 6 // 7 // This file is part of the GNU ISO C++ Library. This library is free 8 // software; you can redistribute it and/or modify it under the 9 // terms of the GNU General Public License as published by the 10 // Free Software Foundation; either version 3, or (at your option) 11 // any later version. 12 // 13 // This library is distributed in the hope that it will be useful, 14 // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 // GNU General Public License for more details. 17 // 18 // You should have received a copy of the GNU General Public License along 19 // with this library; see the file COPYING3. If not see 20 // <http://www.gnu.org/licenses/>. 21 22 #include <utility> 23 #include <testsuite_hooks.h> 24 25 struct noexcept_move_copy 26 { noexcept_move_copynoexcept_move_copy27 noexcept_move_copy() 28 : status(true) 29 { }; 30 noexcept_move_copynoexcept_move_copy31 noexcept_move_copy(noexcept_move_copy&& r) noexcept 32 { r.status = false; }; 33 34 noexcept_move_copy(const noexcept_move_copy&) = default; 35 operator boolnoexcept_move_copy36 operator bool() { return status; } 37 38 private: 39 bool status; 40 }; 41 42 struct noexcept_move_no_copy 43 { noexcept_move_no_copynoexcept_move_no_copy44 noexcept_move_no_copy() 45 : status(true) 46 { }; 47 noexcept_move_no_copynoexcept_move_no_copy48 noexcept_move_no_copy(noexcept_move_no_copy&& r) noexcept 49 { r.status = false; }; 50 51 noexcept_move_no_copy(const noexcept_move_no_copy&) = delete; 52 operator boolnoexcept_move_no_copy53 operator bool() { return status; } 54 55 private: 56 bool status; 57 }; 58 59 struct except_move_copy 60 { except_move_copyexcept_move_copy61 except_move_copy() 62 : status(true) 63 { }; 64 except_move_copyexcept_move_copy65 except_move_copy(except_move_copy&& r) noexcept(false) 66 { r.status = false; }; 67 68 except_move_copy(const except_move_copy&) = default; 69 operator boolexcept_move_copy70 operator bool() { return status; } 71 72 private: 73 bool status; 74 }; 75 76 struct except_move_no_copy 77 { except_move_no_copyexcept_move_no_copy78 except_move_no_copy() 79 : status(true) 80 { }; 81 except_move_no_copyexcept_move_no_copy82 except_move_no_copy(except_move_no_copy&& r) noexcept(false) 83 { r.status = false; }; 84 85 except_move_no_copy(const except_move_no_copy&) = delete; 86 operator boolexcept_move_no_copy87 operator bool() { return status; } 88 89 private: 90 bool status; 91 }; 92 93 void test01()94test01() 95 { 96 noexcept_move_copy nemc1; 97 auto nemc2 __attribute__((unused)) = std::move_if_noexcept(nemc1); 98 VERIFY( nemc1 == false ); 99 100 noexcept_move_no_copy nemnc1; 101 auto nemnc2 __attribute__((unused)) = std::move_if_noexcept(nemnc1); 102 VERIFY( nemnc1 == false ); 103 104 except_move_copy emc1; 105 auto emc2 __attribute__((unused)) = std::move_if_noexcept(emc1); 106 VERIFY( emc1 == true ); 107 108 except_move_no_copy emnc1; 109 auto emnc2 __attribute__((unused)) = std::move_if_noexcept(emnc1); 110 VERIFY( emnc1 == false ); 111 } 112 main()113int main() 114 { 115 test01(); 116 return 0; 117 } 118