00-future-2023-11-30-fix-std-expected-DEVTOOLSSUPPORT-54349.patch 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. diff --git a/include/__expected/expected.h b/include/__expected/expected.h
  2. index 045370a..bf16c8f 100644
  3. --- a/include/__expected/expected.h
  4. +++ b/include/__expected/expected.h
  5. @@ -119,9 +119,7 @@ public:
  6. _LIBCPP_HIDE_FROM_ABI constexpr expected()
  7. noexcept(is_nothrow_default_constructible_v<_Tp>) // strengthened
  8. requires is_default_constructible_v<_Tp>
  9. - : __has_val_(true) {
  10. - std::construct_at(std::addressof(__union_.__val_));
  11. - }
  12. + : __union_(std::in_place), __has_val_(true) {}
  13. _LIBCPP_HIDE_FROM_ABI constexpr expected(const expected&) = delete;
  14. @@ -136,14 +134,7 @@ public:
  15. noexcept(is_nothrow_copy_constructible_v<_Tp> && is_nothrow_copy_constructible_v<_Err>) // strengthened
  16. requires(is_copy_constructible_v<_Tp> && is_copy_constructible_v<_Err> &&
  17. !(is_trivially_copy_constructible_v<_Tp> && is_trivially_copy_constructible_v<_Err>))
  18. - : __has_val_(__other.__has_val_) {
  19. - if (__has_val_) {
  20. - std::construct_at(std::addressof(__union_.__val_), __other.__union_.__val_);
  21. - } else {
  22. - std::construct_at(std::addressof(__union_.__unex_), __other.__union_.__unex_);
  23. - }
  24. - }
  25. -
  26. + : __union_(__other.__has_val_, __other.__union_), __has_val_(__other.__has_val_) { }
  27. _LIBCPP_HIDE_FROM_ABI constexpr expected(expected&&)
  28. requires(is_move_constructible_v<_Tp> && is_move_constructible_v<_Err>
  29. @@ -154,13 +145,7 @@ public:
  30. noexcept(is_nothrow_move_constructible_v<_Tp> && is_nothrow_move_constructible_v<_Err>)
  31. requires(is_move_constructible_v<_Tp> && is_move_constructible_v<_Err> &&
  32. !(is_trivially_move_constructible_v<_Tp> && is_trivially_move_constructible_v<_Err>))
  33. - : __has_val_(__other.__has_val_) {
  34. - if (__has_val_) {
  35. - std::construct_at(std::addressof(__union_.__val_), std::move(__other.__union_.__val_));
  36. - } else {
  37. - std::construct_at(std::addressof(__union_.__unex_), std::move(__other.__union_.__unex_));
  38. - }
  39. - }
  40. + : __union_(__other.__has_val_, std::move(__other.__union_)), __has_val_(__other.__has_val_) { }
  41. private:
  42. template <class _Up, class _OtherErr, class _UfQual, class _OtherErrQual>
  43. @@ -200,26 +185,14 @@ public:
  44. expected(const expected<_Up, _OtherErr>& __other)
  45. noexcept(is_nothrow_constructible_v<_Tp, const _Up&> &&
  46. is_nothrow_constructible_v<_Err, const _OtherErr&>) // strengthened
  47. - : __has_val_(__other.__has_val_) {
  48. - if (__has_val_) {
  49. - std::construct_at(std::addressof(__union_.__val_), __other.__union_.__val_);
  50. - } else {
  51. - std::construct_at(std::addressof(__union_.__unex_), __other.__union_.__unex_);
  52. - }
  53. - }
  54. + : __union_(__other.__has_val_, __other.__union_), __has_val_(__other.__has_val_) {}
  55. template <class _Up, class _OtherErr>
  56. requires __can_convert<_Up, _OtherErr, _Up, _OtherErr>::value
  57. _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v<_Up, _Tp> || !is_convertible_v<_OtherErr, _Err>)
  58. expected(expected<_Up, _OtherErr>&& __other)
  59. noexcept(is_nothrow_constructible_v<_Tp, _Up> && is_nothrow_constructible_v<_Err, _OtherErr>) // strengthened
  60. - : __has_val_(__other.__has_val_) {
  61. - if (__has_val_) {
  62. - std::construct_at(std::addressof(__union_.__val_), std::move(__other.__union_.__val_));
  63. - } else {
  64. - std::construct_at(std::addressof(__union_.__unex_), std::move(__other.__union_.__unex_));
  65. - }
  66. - }
  67. + : __union_(__other.__has_val_, std::move(__other.__union_)), __has_val_(__other.__has_val_) {}
  68. template <class _Up = _Tp>
  69. requires(!is_same_v<remove_cvref_t<_Up>, in_place_t> && !is_same_v<expected, remove_cvref_t<_Up>> &&
  70. @@ -227,61 +200,47 @@ public:
  71. (!is_same_v<remove_cv_t<_Tp>, bool> || !__is_std_expected<remove_cvref_t<_Up>>::value))
  72. _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v<_Up, _Tp>)
  73. expected(_Up&& __u) noexcept(is_nothrow_constructible_v<_Tp, _Up>) // strengthened
  74. - : __has_val_(true) {
  75. - std::construct_at(std::addressof(__union_.__val_), std::forward<_Up>(__u));
  76. - }
  77. + : __union_(std::in_place, std::forward<_Up>(__u)), __has_val_(true) {}
  78. template <class _OtherErr>
  79. requires is_constructible_v<_Err, const _OtherErr&>
  80. _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v<const _OtherErr&, _Err>)
  81. expected(const unexpected<_OtherErr>& __unex)
  82. noexcept(is_nothrow_constructible_v<_Err, const _OtherErr&>) // strengthened
  83. - : __has_val_(false) {
  84. - std::construct_at(std::addressof(__union_.__unex_), __unex.error());
  85. - }
  86. + : __union_(std::unexpect, __unex.error()), __has_val_(false) {}
  87. template <class _OtherErr>
  88. requires is_constructible_v<_Err, _OtherErr>
  89. _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v<_OtherErr, _Err>)
  90. expected(unexpected<_OtherErr>&& __unex)
  91. noexcept(is_nothrow_constructible_v<_Err, _OtherErr>) // strengthened
  92. - : __has_val_(false) {
  93. - std::construct_at(std::addressof(__union_.__unex_), std::move(__unex.error()));
  94. - }
  95. + : __union_(std::unexpect, std::move(__unex.error())), __has_val_(false) {}
  96. template <class... _Args>
  97. requires is_constructible_v<_Tp, _Args...>
  98. _LIBCPP_HIDE_FROM_ABI constexpr explicit expected(in_place_t, _Args&&... __args)
  99. noexcept(is_nothrow_constructible_v<_Tp, _Args...>) // strengthened
  100. - : __has_val_(true) {
  101. - std::construct_at(std::addressof(__union_.__val_), std::forward<_Args>(__args)...);
  102. - }
  103. + : __union_(std::in_place, std::forward<_Args>(__args)...), __has_val_(true) {}
  104. template <class _Up, class... _Args>
  105. requires is_constructible_v< _Tp, initializer_list<_Up>&, _Args... >
  106. _LIBCPP_HIDE_FROM_ABI constexpr explicit
  107. expected(in_place_t, initializer_list<_Up> __il, _Args&&... __args)
  108. noexcept(is_nothrow_constructible_v<_Tp, initializer_list<_Up>&, _Args...>) // strengthened
  109. - : __has_val_(true) {
  110. - std::construct_at(std::addressof(__union_.__val_), __il, std::forward<_Args>(__args)...);
  111. - }
  112. + : __union_(std::in_place, __il, std::forward<_Args>(__args)...), __has_val_(true) {}
  113. template <class... _Args>
  114. requires is_constructible_v<_Err, _Args...>
  115. _LIBCPP_HIDE_FROM_ABI constexpr explicit expected(unexpect_t, _Args&&... __args)
  116. - noexcept(is_nothrow_constructible_v<_Err, _Args...>) // strengthened
  117. - : __has_val_(false) {
  118. - std::construct_at(std::addressof(__union_.__unex_), std::forward<_Args>(__args)...);
  119. - }
  120. + noexcept(is_nothrow_constructible_v<_Err, _Args...>) // strengthened
  121. + : __union_(std::unexpect, std::forward<_Args>(__args)...), __has_val_(false) {}
  122. template <class _Up, class... _Args>
  123. requires is_constructible_v< _Err, initializer_list<_Up>&, _Args... >
  124. _LIBCPP_HIDE_FROM_ABI constexpr explicit
  125. expected(unexpect_t, initializer_list<_Up> __il, _Args&&... __args)
  126. noexcept(is_nothrow_constructible_v<_Err, initializer_list<_Up>&, _Args...>) // strengthened
  127. - : __has_val_(false) {
  128. - std::construct_at(std::addressof(__union_.__unex_), __il, std::forward<_Args>(__args)...);
  129. - }
  130. + : __union_(std::unexpect, __il, std::forward<_Args>(__args)...), __has_val_(false) {}
  131. // [expected.object.dtor], destructor
  132. @@ -440,9 +399,10 @@ public:
  133. std::destroy_at(std::addressof(__union_.__val_));
  134. } else {
  135. std::destroy_at(std::addressof(__union_.__unex_));
  136. - __has_val_ = true;
  137. }
  138. - return *std::construct_at(std::addressof(__union_.__val_), std::forward<_Args>(__args)...);
  139. + std::construct_at(std::addressof(__union_.__val_), std::forward<_Args>(__args)...);
  140. + __has_val_ = true;
  141. + return __union_.__val_;
  142. }
  143. template <class _Up, class... _Args>
  144. @@ -452,9 +412,10 @@ public:
  145. std::destroy_at(std::addressof(__union_.__val_));
  146. } else {
  147. std::destroy_at(std::addressof(__union_.__unex_));
  148. - __has_val_ = true;
  149. }
  150. - return *std::construct_at(std::addressof(__union_.__val_), __il, std::forward<_Args>(__args)...);
  151. + std::construct_at(std::addressof(__union_.__val_), __il, std::forward<_Args>(__args)...);
  152. + __has_val_ = true;
  153. + return __union_.__val_;
  154. }
  155. @@ -893,11 +854,15 @@ public:
  156. }
  157. private:
  158. - struct __empty_t {};
  159. -
  160. template <class _ValueType, class _ErrorType>
  161. union __union_t {
  162. - _LIBCPP_HIDE_FROM_ABI constexpr __union_t() {}
  163. + template <class... _Args>
  164. + _LIBCPP_HIDE_FROM_ABI constexpr explicit __union_t(std::in_place_t, _Args&&... __args)
  165. + : __val_(std::forward<_Args>(__args)...) {}
  166. +
  167. + template <class... _Args>
  168. + _LIBCPP_HIDE_FROM_ABI constexpr explicit __union_t(std::unexpect_t, _Args&&... __args)
  169. + : __unex_(std::forward<_Args>(__args)...) {}
  170. template <class _Func, class... _Args>
  171. _LIBCPP_HIDE_FROM_ABI constexpr explicit __union_t(
  172. @@ -909,6 +874,14 @@ private:
  173. std::__expected_construct_unexpected_from_invoke_tag, _Func&& __f, _Args&&... __args)
  174. : __unex_(std::invoke(std::forward<_Func>(__f), std::forward<_Args>(__args)...)) {}
  175. + template <class _Union>
  176. + _LIBCPP_HIDE_FROM_ABI constexpr explicit __union_t(bool __has_val, _Union&& __other) {
  177. + if (__has_val)
  178. + std::construct_at(std::addressof(__val_), std::forward<_Union>(__other).__val_);
  179. + else
  180. + std::construct_at(std::addressof(__unex_), std::forward<_Union>(__other).__unex_);
  181. + }
  182. +
  183. _LIBCPP_HIDE_FROM_ABI constexpr ~__union_t()
  184. requires(is_trivially_destructible_v<_ValueType> && is_trivially_destructible_v<_ErrorType>)
  185. = default;
  186. @@ -927,10 +900,17 @@ private:
  187. template <class _ValueType, class _ErrorType>
  188. requires(is_trivially_move_constructible_v<_ValueType> && is_trivially_move_constructible_v<_ErrorType>)
  189. union __union_t<_ValueType, _ErrorType> {
  190. - _LIBCPP_HIDE_FROM_ABI constexpr __union_t() : __empty_() {}
  191. _LIBCPP_HIDE_FROM_ABI constexpr __union_t(const __union_t&) = default;
  192. _LIBCPP_HIDE_FROM_ABI constexpr __union_t& operator=(const __union_t&) = default;
  193. + template <class... _Args>
  194. + _LIBCPP_HIDE_FROM_ABI constexpr explicit __union_t(std::in_place_t, _Args&&... __args)
  195. + : __val_(std::forward<_Args>(__args)...) {}
  196. +
  197. + template <class... _Args>
  198. + _LIBCPP_HIDE_FROM_ABI constexpr explicit __union_t(std::unexpect_t, _Args&&... __args)
  199. + : __unex_(std::forward<_Args>(__args)...) {}
  200. +
  201. template <class _Func, class... _Args>
  202. _LIBCPP_HIDE_FROM_ABI constexpr explicit __union_t(
  203. std::__expected_construct_in_place_from_invoke_tag, _Func&& __f, _Args&&... __args)
  204. @@ -941,6 +921,14 @@ private:
  205. std::__expected_construct_unexpected_from_invoke_tag, _Func&& __f, _Args&&... __args)
  206. : __unex_(std::invoke(std::forward<_Func>(__f), std::forward<_Args>(__args)...)) {}
  207. + template <class _Union>
  208. + _LIBCPP_HIDE_FROM_ABI constexpr explicit __union_t(bool __has_val, _Union&& __other) {
  209. + if (__has_val)
  210. + std::construct_at(std::addressof(__val_), std::forward<_Union>(__other).__val_);
  211. + else
  212. + std::construct_at(std::addressof(__unex_), std::forward<_Union>(__other).__unex_);
  213. + }
  214. +
  215. _LIBCPP_HIDE_FROM_ABI constexpr ~__union_t()
  216. requires(is_trivially_destructible_v<_ValueType> && is_trivially_destructible_v<_ErrorType>)
  217. = default;
  218. @@ -950,7 +938,6 @@ private:
  219. requires(!is_trivially_destructible_v<_ValueType> || !is_trivially_destructible_v<_ErrorType>)
  220. {}
  221. - _LIBCPP_NO_UNIQUE_ADDRESS __empty_t __empty_;
  222. _LIBCPP_NO_UNIQUE_ADDRESS _ValueType __val_;
  223. _LIBCPP_NO_UNIQUE_ADDRESS _ErrorType __unex_;
  224. };
  225. @@ -998,11 +985,7 @@ public:
  226. _LIBCPP_HIDE_FROM_ABI constexpr expected(const expected& __rhs)
  227. noexcept(is_nothrow_copy_constructible_v<_Err>) // strengthened
  228. requires(is_copy_constructible_v<_Err> && !is_trivially_copy_constructible_v<_Err>)
  229. - : __has_val_(__rhs.__has_val_) {
  230. - if (!__rhs.__has_val_) {
  231. - std::construct_at(std::addressof(__union_.__unex_), __rhs.__union_.__unex_);
  232. - }
  233. - }
  234. + : __union_(__rhs.__has_val_, __rhs.__union_), __has_val_(__rhs.__has_val_) {}
  235. _LIBCPP_HIDE_FROM_ABI constexpr expected(expected&&)
  236. requires(is_move_constructible_v<_Err> && is_trivially_move_constructible_v<_Err>)
  237. @@ -1011,51 +994,35 @@ public:
  238. _LIBCPP_HIDE_FROM_ABI constexpr expected(expected&& __rhs)
  239. noexcept(is_nothrow_move_constructible_v<_Err>)
  240. requires(is_move_constructible_v<_Err> && !is_trivially_move_constructible_v<_Err>)
  241. - : __has_val_(__rhs.__has_val_) {
  242. - if (!__rhs.__has_val_) {
  243. - std::construct_at(std::addressof(__union_.__unex_), std::move(__rhs.__union_.__unex_));
  244. - }
  245. - }
  246. + : __union_(__rhs.__has_val_, std::move(__rhs.__union_)), __has_val_(__rhs.__has_val_) {}
  247. template <class _Up, class _OtherErr>
  248. requires __can_convert<_Up, _OtherErr, const _OtherErr&>::value
  249. _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v<const _OtherErr&, _Err>)
  250. expected(const expected<_Up, _OtherErr>& __rhs)
  251. noexcept(is_nothrow_constructible_v<_Err, const _OtherErr&>) // strengthened
  252. - : __has_val_(__rhs.__has_val_) {
  253. - if (!__rhs.__has_val_) {
  254. - std::construct_at(std::addressof(__union_.__unex_), __rhs.__union_.__unex_);
  255. - }
  256. - }
  257. + : __union_(__rhs.__has_val_, __rhs.__union_), __has_val_(__rhs.__has_val_) {}
  258. template <class _Up, class _OtherErr>
  259. requires __can_convert<_Up, _OtherErr, _OtherErr>::value
  260. _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v<_OtherErr, _Err>)
  261. expected(expected<_Up, _OtherErr>&& __rhs)
  262. noexcept(is_nothrow_constructible_v<_Err, _OtherErr>) // strengthened
  263. - : __has_val_(__rhs.__has_val_) {
  264. - if (!__rhs.__has_val_) {
  265. - std::construct_at(std::addressof(__union_.__unex_), std::move(__rhs.__union_.__unex_));
  266. - }
  267. - }
  268. + : __union_(__rhs.__has_val_, std::move(__rhs.__union_)), __has_val_(__rhs.__has_val_) {}
  269. template <class _OtherErr>
  270. requires is_constructible_v<_Err, const _OtherErr&>
  271. _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v<const _OtherErr&, _Err>)
  272. expected(const unexpected<_OtherErr>& __unex)
  273. noexcept(is_nothrow_constructible_v<_Err, const _OtherErr&>) // strengthened
  274. - : __has_val_(false) {
  275. - std::construct_at(std::addressof(__union_.__unex_), __unex.error());
  276. - }
  277. + : __union_(std::unexpect, __unex.error()), __has_val_(false) {}
  278. template <class _OtherErr>
  279. requires is_constructible_v<_Err, _OtherErr>
  280. _LIBCPP_HIDE_FROM_ABI constexpr explicit(!is_convertible_v<_OtherErr, _Err>)
  281. expected(unexpected<_OtherErr>&& __unex)
  282. noexcept(is_nothrow_constructible_v<_Err, _OtherErr>) // strengthened
  283. - : __has_val_(false) {
  284. - std::construct_at(std::addressof(__union_.__unex_), std::move(__unex.error()));
  285. - }
  286. + : __union_(std::unexpect, std::move(__unex.error())), __has_val_(false) {}
  287. _LIBCPP_HIDE_FROM_ABI constexpr explicit expected(in_place_t) noexcept : __has_val_(true) {}
  288. @@ -1063,17 +1030,13 @@ public:
  289. requires is_constructible_v<_Err, _Args...>
  290. _LIBCPP_HIDE_FROM_ABI constexpr explicit expected(unexpect_t, _Args&&... __args)
  291. noexcept(is_nothrow_constructible_v<_Err, _Args...>) // strengthened
  292. - : __has_val_(false) {
  293. - std::construct_at(std::addressof(__union_.__unex_), std::forward<_Args>(__args)...);
  294. - }
  295. + : __union_(std::unexpect, std::forward<_Args>(__args)...), __has_val_(false) {}
  296. template <class _Up, class... _Args>
  297. requires is_constructible_v< _Err, initializer_list<_Up>&, _Args... >
  298. _LIBCPP_HIDE_FROM_ABI constexpr explicit expected(unexpect_t, initializer_list<_Up> __il, _Args&&... __args)
  299. noexcept(is_nothrow_constructible_v<_Err, initializer_list<_Up>&, _Args...>) // strengthened
  300. - : __has_val_(false) {
  301. - std::construct_at(std::addressof(__union_.__unex_), __il, std::forward<_Args>(__args)...);
  302. - }
  303. + : __union_(std::unexpect, __il, std::forward<_Args>(__args)...), __has_val_(false) {}
  304. private:
  305. template <class _Func>
  306. @@ -1507,11 +1470,23 @@ private:
  307. union __union_t {
  308. _LIBCPP_HIDE_FROM_ABI constexpr __union_t() : __empty_() {}
  309. + template <class... _Args>
  310. + _LIBCPP_HIDE_FROM_ABI constexpr explicit __union_t(std::unexpect_t, _Args&&... __args)
  311. + : __unex_(std::forward<_Args>(__args)...) {}
  312. +
  313. template <class _Func, class... _Args>
  314. _LIBCPP_HIDE_FROM_ABI constexpr explicit __union_t(
  315. __expected_construct_unexpected_from_invoke_tag, _Func&& __f, _Args&&... __args)
  316. : __unex_(std::invoke(std::forward<_Func>(__f), std::forward<_Args>(__args)...)) {}
  317. + template <class _Union>
  318. + _LIBCPP_HIDE_FROM_ABI constexpr explicit __union_t(bool __has_val, _Union&& __other) {
  319. + if (__has_val)
  320. + std::construct_at(std::addressof(__empty_));
  321. + else
  322. + std::construct_at(std::addressof(__unex_), std::forward<_Union>(__other).__unex_);
  323. + }
  324. +
  325. _LIBCPP_HIDE_FROM_ABI constexpr ~__union_t()
  326. requires(is_trivially_destructible_v<_ErrorType>)
  327. = default;
  328. @@ -1534,11 +1509,23 @@ private:
  329. _LIBCPP_HIDE_FROM_ABI constexpr __union_t(const __union_t&) = default;
  330. _LIBCPP_HIDE_FROM_ABI constexpr __union_t& operator=(const __union_t&) = default;
  331. + template <class... _Args>
  332. + _LIBCPP_HIDE_FROM_ABI constexpr explicit __union_t(std::unexpect_t, _Args&&... __args)
  333. + : __unex_(std::forward<_Args>(__args)...) {}
  334. +
  335. template <class _Func, class... _Args>
  336. _LIBCPP_HIDE_FROM_ABI constexpr explicit __union_t(
  337. __expected_construct_unexpected_from_invoke_tag, _Func&& __f, _Args&&... __args)
  338. : __unex_(std::invoke(std::forward<_Func>(__f), std::forward<_Args>(__args)...)) {}
  339. + template <class _Union>
  340. + _LIBCPP_HIDE_FROM_ABI constexpr explicit __union_t(bool __has_val, _Union&& __other) {
  341. + if (__has_val)
  342. + std::construct_at(std::addressof(__empty_));
  343. + else
  344. + std::construct_at(std::addressof(__unex_), std::forward<_Union>(__other).__unex_);
  345. + }
  346. +
  347. _LIBCPP_HIDE_FROM_ABI constexpr ~__union_t()
  348. requires(is_trivially_destructible_v<_ErrorType>)
  349. = default;