]>
Commit | Line | Data |
---|---|---|
ec2ec24a | 1 | // { dg-do run { target c++23 } } |
a945c346 | 2 | // Copyright (C) 2023-2024 Free Software Foundation, Inc. |
ec2ec24a AA |
3 | // |
4 | // This file is part of the GNU ISO C++ Library. This library is free | |
5 | // software; you can redistribute it and/or modify it under the | |
6 | // terms of the GNU General Public License as published by the | |
7 | // Free Software Foundation; either version 3, or (at your option) | |
8 | // any later version. | |
9 | ||
10 | // This library is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | ||
15 | // Under Section 7 of GPL version 3, you are granted additional | |
16 | // permissions described in the GCC Runtime Library Exception, version | |
17 | // 3.1, as published by the Free Software Foundation. | |
18 | ||
19 | // You should have received a copy of the GNU General Public License and | |
20 | // a copy of the GCC Runtime Library Exception along with this program; | |
21 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
22 | // <http://www.gnu.org/licenses/>. | |
23 | ||
24 | #include <testsuite_hooks.h> | |
25 | #include <generator> | |
26 | ||
27 | template<unsigned MaxCopies> | |
28 | struct copy_max | |
29 | { | |
30 | int copy = 0; | |
31 | ||
32 | copy_max() | |
33 | {} | |
34 | ||
35 | copy_max(const copy_max& o) | |
36 | : copy {o.copy + 1} | |
37 | { | |
38 | VERIFY(copy <= MaxCopies); | |
39 | } | |
40 | ||
41 | copy_max& | |
42 | operator=(const copy_max& o) | |
43 | { | |
44 | copy = o.copy + 1; | |
45 | VERIFY(copy <= MaxCopies); | |
46 | return *this; | |
47 | } | |
48 | ||
49 | copy_max(copy_max&& o) | |
50 | { | |
51 | std::swap(o.copy, this->copy); | |
52 | } | |
53 | ||
54 | copy_max& | |
55 | operator=(copy_max&& o) | |
56 | { | |
57 | std::swap(o.copy, this->copy); | |
58 | return *this; | |
59 | } | |
60 | }; | |
61 | ||
62 | template<typename Ref> | |
63 | std::generator<Ref> | |
64 | foo() | |
65 | { | |
66 | co_yield {}; | |
67 | } | |
68 | ||
69 | int | |
70 | main() | |
71 | { | |
72 | static_assert(!std::copy_constructible<std::generator<int>>); | |
73 | { | |
74 | auto gen = foo<const copy_max<1>&>(); | |
75 | auto i = gen.begin(); | |
76 | *i; | |
77 | *i; | |
78 | auto is = *i; | |
79 | VERIFY(is.copy > 0); | |
80 | } | |
81 | ||
82 | { | |
83 | auto gen2 = foo<copy_max<0>&&>(); | |
84 | auto i = gen2.begin(); | |
85 | *i; | |
86 | *i; | |
87 | auto is = *i; | |
88 | } | |
89 | ||
90 | { | |
91 | auto gen = foo<copy_max<0>>(); // should be same as case 2 | |
92 | auto i = gen.begin(); | |
93 | *i; | |
94 | *i; | |
95 | auto is = *i; | |
96 | } | |
97 | } |