summaryrefslogtreecommitdiff
path: root/dev-libs/boost/files/boost-1.91.0-optional-bool-copy-ctor.patch
blob: adb29893c3ec26a1ca0bdab53ba06ca8ee009c42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
Bug: https://github.com/boostorg/optional/issues/146
Patch: https://github.com/boostorg/optional/commit/1fb60cb53bb2b86b2a9739a26a8be2c5e4c9e8fc
File paths adapted to match dist layout.

From: Andrzej Krzemienski <akrzemi1@gmail.com>
Date: Sun, 26 Apr 2026 21:57:08 +0200
Subject: [PATCH] fix bug in copy construction of optional<bool>

--- a/libs/optional/doc/92_relnotes.qbk
+++ b/libs/optional/doc/92_relnotes.qbk
@@ -11,6 +11,10 @@
 
 [section:relnotes Release Notes]
 
+[heading Boost Release 1.xx]
+
+* Fixed regression in the copy-initialization of `optional<bool>`. This fixes [@https://github.com/boostorg/optional/issues/146 issue #146].
+
 [heading Boost Release 1.91]
 
 * For compilers with full C++11 support (including "unrestricted  unions" and ref-qualifiers)
diff --git a/include/boost/optional/detail/optional_select_implementation.hpp b/include/boost/optional/detail/optional_select_implementation.hpp
index 8a69eeac..53a75f87 100644
--- a/boost/optional/detail/optional_select_implementation.hpp
+++ b/boost/optional/detail/optional_select_implementation.hpp
@@ -23,7 +23,8 @@
     !defined(BOOST_NO_CXX11_TRAILING_RESULT_TYPES) && \
     !defined(BOOST_NO_CXX11_UNRESTRICTED_UNION) &&    \
     !defined(BOOST_NO_CXX11_NOEXCEPT) &&              \
-    !defined(BOOST_NO_CXX11_DEFAULTED_MOVES)
+    !defined(BOOST_NO_CXX11_DEFAULTED_MOVES) &&       \
+    !defined(BOOST_OPTIONAL_CONFIG_DISABLE_UNION_OPTIONAL)
 # define BOOST_OPTIONAL_USES_UNION_IMPLEMENTATION
 #endif
 
diff --git a/include/boost/optional/detail/union_optional.hpp b/include/boost/optional/detail/union_optional.hpp
index 16e150f4..b735d5ab 100644
--- a/boost/optional/detail/union_optional.hpp
+++ b/boost/optional/detail/union_optional.hpp
@@ -391,7 +391,9 @@ namespace boost {
     template <typename U,
               BOOST_OPTIONAL_REQUIRES(::std::is_constructible<T, U&&>),
               BOOST_OPTIONAL_REQUIRES(!optional_detail::is_typed_in_place_factory<U>),
-              BOOST_OPTIONAL_REQUIRES(!optional_detail::is_in_place_factory<U>)>
+              BOOST_OPTIONAL_REQUIRES(!optional_detail::is_in_place_factory<U>),
+              BOOST_OPTIONAL_REQUIRES(!BOOST_OPTIONAL_IS_TAGGED(optional_detail::optional_tag, U))
+              >
     constexpr explicit optional(U&& v)
     : storage(optional_ns::in_place_init, optional_detail::forward_<U>(v))
     {}
diff --git a/test/Jamfile.v2 b/test/Jamfile.v2
index f625e581..c17a7110 100644
--- a/libs/optional/test/Jamfile.v2
+++ b/libs/optional/test/Jamfile.v2
@@ -40,6 +40,7 @@ compile optional_test_constexpr.cpp ;
 compile optional_test_wuninitialized.cpp ;
 compile optional_test_fwd_header.cpp ;
 run optional_test_conversions_from_U.cpp ;
+run optional_test_constructors.cpp ;
 run optional_test_convert_from_T.cpp ;
 run optional_test_convert_assign.cpp ;
 run optional_test_empty_braces.cpp ;
diff --git a/test/optional_test_constructors.cpp b/test/optional_test_constructors.cpp
new file mode 100644
index 00000000..e3483a69
--- /dev/null
+++ b/libs/optional/test/optional_test_constructors.cpp
@@ -0,0 +1,287 @@
+// Copyright (C) 2026 Andrzej Krzemienski.
+//
+// Use, modification, and distribution is subject to the Boost Software
+// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/lib/optional for documentation.
+//
+// You are welcome to contact the author at:
+//  akrzemi1@gmail.com
+
+#include "boost/optional/optional.hpp"
+#include "boost/core/lightweight_test.hpp"
+#include <string>
+
+
+using boost::optional;
+using boost::none;
+
+struct MyBool
+{
+  bool b;
+  MyBool (bool b) : b(b) {}
+  operator bool() const { return b; };
+};
+
+struct MyExplicitBool
+{
+  bool b;
+  MyExplicitBool (bool b) : b(b) {}
+  operator bool() const { return b; };
+};
+
+struct Any
+{
+  template <typename... T>
+  Any(T&&...) {}
+};
+
+struct JustCopyMoveCtor
+{
+  JustCopyMoveCtor(JustCopyMoveCtor&&) = default;
+  JustCopyMoveCtor(JustCopyMoveCtor const&) = default;
+  JustCopyMoveCtor& operator=(JustCopyMoveCtor&&) = delete;
+  JustCopyMoveCtor& operator=(JustCopyMoveCtor const&) = delete;
+  JustCopyMoveCtor() = delete;
+};
+
+struct JustDefault
+{
+  JustDefault() = default;
+  JustDefault(JustDefault&&) = delete;
+};
+
+template <typename T>
+optional<T> empty_optional()
+{
+    return optional<T>(); // this is to avoid "the most vexing parse"
+}
+
+
+template <typename T, typename U>
+void direct_test_ctor_optional_T_from_empty_optional_T()
+{
+  optional<U> om;
+  const optional<U> oc;
+  BOOST_TEST(!om);
+  BOOST_TEST(!oc);
+
+  {
+    optional<T> ox = om;
+    BOOST_TEST(!ox);
+
+    optional<T> oy = oc;
+    BOOST_TEST(!oy);
+
+    optional<T> oz = empty_optional<U>();
+    BOOST_TEST(!oz);
+  }
+
+  {
+    optional<T> ox = {om};
+    BOOST_TEST(!ox);
+
+    optional<T> oy = {oc};
+    BOOST_TEST(!oy);
+
+    optional<T> oz = {empty_optional<U>()};
+    BOOST_TEST(!oz);
+  }
+
+  {
+    optional<T> ox{om};
+    BOOST_TEST(!ox);
+
+    optional<T> oy{oc};
+    BOOST_TEST(!oy);
+
+    optional<T> oz{empty_optional<U>()};
+    BOOST_TEST(!oz);
+  }
+
+  {
+    optional<T> ox(om);
+    BOOST_TEST(!ox);
+
+    optional<T> oy(oc);
+    BOOST_TEST(!oy);
+
+    optional<T> oz(empty_optional<U>());
+    BOOST_TEST(!oz);
+  }
+}
+
+template <typename T, typename U>
+void test_ctor_optional_T_from_empty_optional_T()
+{
+  direct_test_ctor_optional_T_from_empty_optional_T<T, U>();
+  direct_test_ctor_optional_T_from_empty_optional_T<const T, const U>();
+  direct_test_ctor_optional_T_from_empty_optional_T<optional<T>, optional<U>>();
+  direct_test_ctor_optional_T_from_empty_optional_T<optional<const T>, optional<const U>>();
+  direct_test_ctor_optional_T_from_empty_optional_T<const optional<T>, const optional<U>>();
+}
+
+template <typename T, typename U>
+void direct_test_ctor_optional_T_from_optional_U(U val)
+{
+  optional<U> om;
+  const optional<U> oc;
+  BOOST_TEST(!om);
+  BOOST_TEST(!oc);
+
+  {
+    optional<T> ox{om};
+    BOOST_TEST(!ox);
+
+    optional<T> oy{oc};
+    BOOST_TEST(!oy);
+
+    optional<T> oz{empty_optional<U>()};
+    BOOST_TEST(!oz);
+  }
+
+  {
+    optional<T> ox(om);
+    BOOST_TEST(!ox);
+
+    optional<T> oy(oc);
+    BOOST_TEST(!oy);
+
+    optional<T> oz(empty_optional<U>());
+    BOOST_TEST(!oz);
+  }
+
+  {
+    optional<U> om {val};
+    const optional<U> oc {val};
+
+    {
+      optional<T> ox{om};
+      BOOST_TEST(ox);
+
+      optional<T> oy{oc};
+      BOOST_TEST(oy);
+
+      optional<T> oz{boost::make_optional(val)};
+      BOOST_TEST(oz);
+    }
+    {
+      optional<T> ox(om);
+      BOOST_TEST(ox);
+
+      optional<T> oy(oc);
+      BOOST_TEST(oy);
+
+      optional<T> oz(boost::make_optional(val));
+      BOOST_TEST(oz);
+    }
+  }
+}
+
+template <typename T, typename U>
+void test_ctor_optional_T_from_optional_U(U val)
+{
+  direct_test_ctor_optional_T_from_optional_U<T>(val);
+}
+
+template <typename T>
+void direct_test_ctor_optional_T_from_valued_optional_T(T val)
+{
+  optional<T> om(val);
+  const optional<T> oc(val);
+  BOOST_TEST(om);
+  BOOST_TEST(oc);
+
+  {
+    optional<T> ox = om;
+    BOOST_TEST(ox);
+
+    optional<T> oy = oc;
+    BOOST_TEST(oy);
+
+    optional<T> oz = optional<T>(val);
+    BOOST_TEST(oz);
+  }
+  {
+    optional<T> ox = {om};
+    BOOST_TEST(ox);
+
+    optional<T> oy = {oc};
+    BOOST_TEST(oy);
+
+    optional<T> oz = {optional<T>(val)};
+    BOOST_TEST(oz);
+  }
+}
+
+template <typename T>
+void test_ctor_optional_T_from_valued_optional_T(T val)
+{
+  direct_test_ctor_optional_T_from_valued_optional_T<T>(val);
+  direct_test_ctor_optional_T_from_valued_optional_T<optional<T>>(val);
+  direct_test_ctor_optional_T_from_valued_optional_T<const T>(val);
+  direct_test_ctor_optional_T_from_optional_U<T, T>(val);
+  direct_test_ctor_optional_T_from_optional_U<optional<T>, optional<T>>(val);
+}
+
+template <typename T>
+void direct_test_inplace_tag_constructor()
+{
+  {
+    optional<T> ox (boost::in_place_init);
+    BOOST_TEST(ox);
+  }
+  {
+    optional<T> ox {boost::in_place_init};
+    BOOST_TEST(ox);
+  }
+}
+
+template <typename T>
+void test_inplace_tag_constructor()
+{
+  direct_test_inplace_tag_constructor<T>();
+  direct_test_inplace_tag_constructor<optional<T>>();
+}
+
+
+int main()
+{
+    test_ctor_optional_T_from_empty_optional_T<int, int>();
+    test_ctor_optional_T_from_empty_optional_T<long, long>();
+    test_ctor_optional_T_from_empty_optional_T<std::string, std::string>();
+    test_ctor_optional_T_from_empty_optional_T<JustCopyMoveCtor, JustCopyMoveCtor>();
+    test_ctor_optional_T_from_empty_optional_T<MyBool, MyBool>();
+
+    test_ctor_optional_T_from_empty_optional_T<MyExplicitBool, MyExplicitBool>();
+
+    test_ctor_optional_T_from_empty_optional_T<bool, bool>();
+    test_ctor_optional_T_from_empty_optional_T<Any, Any>();
+
+    test_inplace_tag_constructor<int>();
+    test_inplace_tag_constructor<Any>();
+    test_inplace_tag_constructor<JustDefault>();
+
+    test_ctor_optional_T_from_optional_U<int>(1);
+    test_ctor_optional_T_from_optional_U<long>(1);
+    test_ctor_optional_T_from_optional_U<bool>(MyBool{true});
+    test_ctor_optional_T_from_optional_U<bool>(MyBool{false});
+    test_ctor_optional_T_from_optional_U<MyBool>(true);
+    test_ctor_optional_T_from_optional_U<MyBool>(false);
+    test_ctor_optional_T_from_optional_U<bool>(MyExplicitBool{true});
+    test_ctor_optional_T_from_optional_U<bool>(MyExplicitBool{false});
+    test_ctor_optional_T_from_optional_U<MyExplicitBool>(true);
+    test_ctor_optional_T_from_optional_U<MyExplicitBool>(false);
+    test_ctor_optional_T_from_optional_U<Any>(true);
+    test_ctor_optional_T_from_optional_U<Any>(Any{});
+
+    test_ctor_optional_T_from_valued_optional_T(1);
+
+    optional<MyBool> ob;
+    optional<bool> oa;
+    oa = ob;
+    BOOST_TEST(!oa);
+
+    return boost::report_errors();
+}