| 1 |
// { dg-do compile { target c++11 } } |
| 2 |
|
| 3 |
// Copyright (C) 2010-2025 Free Software Foundation, Inc. |
| 4 |
// |
| 5 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 6 |
// software; you can redistribute it and/or modify it under the |
| 7 |
// terms of the GNU General Public License as published by the |
| 8 |
// Free Software Foundation; either version 3, or (at your option) |
| 9 |
// any later version. |
| 10 |
// |
| 11 |
// This library is distributed in the hope that it will be useful, |
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
// GNU General Public License for more details. |
| 15 |
// |
| 16 |
// You should have received a copy of the GNU General Public License along |
| 17 |
// with this library; see the file COPYING3. If not see |
| 18 |
// <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
// { dg-error "convert an rvalue to an lvalue" "" { target *-*-* } 0 } |
| 21 |
|
| 22 |
#include <utility> |
| 23 |
|
| 24 |
template <class T> |
| 25 |
struct C |
| 26 |
{ |
| 27 |
T t_; |
| 28 |
|
| 29 |
C() {} |
| 30 |
|
| 31 |
explicit C(const T& t) : t_(t) { } |
| 32 |
|
| 33 |
template <class U, |
| 34 |
class = typename std::enable_if |
| 35 |
< |
| 36 |
std::is_convertible<U, T>::value |
| 37 |
>::type> |
| 38 |
C(C<U>&& c) : t_(std::forward<T>(c.t_)) { } |
| 39 |
}; |
| 40 |
|
| 41 |
class B; |
| 42 |
|
| 43 |
class A |
| 44 |
{ |
| 45 |
int data_; |
| 46 |
|
| 47 |
friend class B; |
| 48 |
public: |
| 49 |
explicit |
| 50 |
A(int data = 1) |
| 51 |
: data_(data) { } |
| 52 |
|
| 53 |
~A() { data_ = -1; } |
| 54 |
|
| 55 |
void test() const |
| 56 |
{ |
| 57 |
__builtin_abort(); |
| 58 |
} |
| 59 |
}; |
| 60 |
|
| 61 |
class B |
| 62 |
{ |
| 63 |
int data_; |
| 64 |
public: |
| 65 |
explicit |
| 66 |
B(int data = 1) |
| 67 |
: data_(data) { } |
| 68 |
|
| 69 |
B(const A& a) : data_(a.data_) { } |
| 70 |
|
| 71 |
B(A&& a) : data_(a.data_) { a.data_ = 100; } |
| 72 |
|
| 73 |
~B() { data_ = -1; } |
| 74 |
|
| 75 |
void test() const |
| 76 |
{ |
| 77 |
__builtin_abort(); |
| 78 |
} |
| 79 |
}; |
| 80 |
|
| 81 |
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2951.html |
| 82 |
// Test F. |
| 83 |
int main() |
| 84 |
{ |
| 85 |
A a(3); |
| 86 |
C<A> ca(a); |
| 87 |
C<const B&> cb(std::move(ca)); |
| 88 |
cb.t_.test(); |
| 89 |
} |