| 1 | // Copyright (C) 2015-2025 Free Software Foundation, Inc. |
| 2 | // |
| 3 | // This file is part of the GNU ISO C++ Library. This library is free |
| 4 | // software; you can redistribute it and/or modify it under the |
| 5 | // terms of the GNU General Public License as published by the |
| 6 | // Free Software Foundation; either version 3, or (at your option) |
| 7 | // any later version. |
| 8 | |
| 9 | // This library is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | |
| 14 | // You should have received a copy of the GNU General Public License along |
| 15 | // with this library; see the file COPYING3. If not see |
| 16 | // <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | // { dg-do run { target c++11 } } |
| 19 | |
| 20 | #include <memory> |
| 21 | #include <testsuite_hooks.h> |
| 22 | |
| 23 | struct X |
| 24 | { |
| 25 | X() = default; |
| 26 | X(X const &) = default; |
| 27 | X& operator=(X const&) = delete; |
| 28 | }; |
| 29 | |
| 30 | static_assert(__is_trivial(X), "X is trivial"); |
| 31 | |
| 32 | int constructed = 0; |
| 33 | int assigned = 0; |
| 34 | |
| 35 | struct Y |
| 36 | { |
| 37 | Y() = default; |
| 38 | Y(Y const &) = default; |
| 39 | Y& operator=(Y const&) = default; |
| 40 | |
| 41 | Y(const X&) { ++constructed; } |
| 42 | Y& operator=(const X&)& { ++assigned; return *this; } |
| 43 | Y& operator=(const X&)&& = delete; |
| 44 | Y& operator=(X&&) = delete; |
| 45 | }; |
| 46 | |
| 47 | static_assert(__is_trivial(Y), "Y is trivial"); |
| 48 | |
| 49 | void |
| 50 | test01() |
| 51 | { |
| 52 | X a[100]; |
| 53 | Y b[100]; |
| 54 | |
| 55 | std::uninitialized_copy(a, a+10, b); |
| 56 | |
| 57 | // In GCC 14 and older std::uninitialized_copy was optimized to std::copy |
| 58 | // and so used assignments not construction, but that was non-conforming. |
| 59 | VERIFY(constructed == 10); |
| 60 | VERIFY(assigned == 0); |
| 61 | } |
| 62 | |
| 63 | int |
| 64 | main() |
| 65 | { |
| 66 | test01(); |
| 67 | } |