| 1 | // { dg-do run { target c++11 } } |
| 2 | |
| 3 | // 2011-04-27 Paolo Carlini <[email protected]> |
| 4 | // |
| 5 | // Copyright (C) 2011-2025 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 | { |
| 27 | noexcept_move_copy() |
| 28 | : status(true) |
| 29 | { }; |
| 30 | |
| 31 | noexcept_move_copy(noexcept_move_copy&& r) noexcept |
| 32 | { r.status = false; }; |
| 33 | |
| 34 | noexcept_move_copy(const noexcept_move_copy&) = default; |
| 35 | |
| 36 | operator bool() { return status; } |
| 37 | |
| 38 | private: |
| 39 | bool status; |
| 40 | }; |
| 41 | |
| 42 | struct noexcept_move_no_copy |
| 43 | { |
| 44 | noexcept_move_no_copy() |
| 45 | : status(true) |
| 46 | { }; |
| 47 | |
| 48 | 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 | |
| 53 | operator bool() { return status; } |
| 54 | |
| 55 | private: |
| 56 | bool status; |
| 57 | }; |
| 58 | |
| 59 | struct except_move_copy |
| 60 | { |
| 61 | except_move_copy() |
| 62 | : status(true) |
| 63 | { }; |
| 64 | |
| 65 | except_move_copy(except_move_copy&& r) noexcept(false) |
| 66 | { r.status = false; }; |
| 67 | |
| 68 | except_move_copy(const except_move_copy&) = default; |
| 69 | |
| 70 | operator bool() { return status; } |
| 71 | |
| 72 | private: |
| 73 | bool status; |
| 74 | }; |
| 75 | |
| 76 | struct except_move_no_copy |
| 77 | { |
| 78 | except_move_no_copy() |
| 79 | : status(true) |
| 80 | { }; |
| 81 | |
| 82 | 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 | |
| 87 | operator bool() { return status; } |
| 88 | |
| 89 | private: |
| 90 | bool status; |
| 91 | }; |
| 92 | |
| 93 | void |
| 94 | test01() |
| 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 | |
| 113 | int main() |
| 114 | { |
| 115 | test01(); |
| 116 | return 0; |
| 117 | } |