| 1 | // Copyright (C) 2019-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 compile { target c++11 } } |
| 19 | |
| 20 | #include <vector> |
| 21 | |
| 22 | struct T |
| 23 | { |
| 24 | T() { } |
| 25 | T(const T&) { } |
| 26 | T(T&&) = delete; // this means T is not MoveInsertable into std::vector<T> |
| 27 | }; |
| 28 | |
| 29 | void f() |
| 30 | { |
| 31 | const T val; |
| 32 | std::vector<T> x; |
| 33 | // push_back(const T&) only requires T is CopyInsertable into std::vector<T>: |
| 34 | x.push_back(val); |
| 35 | } |
| 36 | |
| 37 | template<typename U> |
| 38 | struct Alloc |
| 39 | { |
| 40 | using value_type = U; |
| 41 | Alloc() = default; |
| 42 | Alloc(const Alloc&) = default; |
| 43 | template<typename U2> |
| 44 | Alloc(const Alloc<U2>&) { } |
| 45 | |
| 46 | U* allocate(unsigned n) { return std::allocator<U>().allocate(n); } |
| 47 | void deallocate(U* p, unsigned n) { std::allocator<U>().deallocate(p, n); } |
| 48 | |
| 49 | void construct(Alloc*, U* p, U&& u) |
| 50 | { |
| 51 | // construct from const lvalue instead of rvalue: |
| 52 | ::new(p) U(const_cast<const U&>(u)); |
| 53 | } |
| 54 | }; |
| 55 | |
| 56 | void g() |
| 57 | { |
| 58 | const T val; |
| 59 | std::vector<T, Alloc<T>> x; |
| 60 | // push_back(const T&) only requires T is CopyInsertable into std::vector<T>: |
| 61 | x.push_back(val); |
| 62 | } |