Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
74f872b
Implement P2231R1 Completing constexpr In optional
miscco Jun 11, 2021
f9e4e18
Implement P2231R1 Completing constexpr in variant
miscco Jun 12, 2021
f77c5aa
Properly test the feature test macros
miscco Jun 12, 2021
0c36ad9
Address review comments
miscco Jun 24, 2021
ca40908
Make the test pass
miscco Jun 24, 2021
09eff91
Fix typo
miscco Jun 24, 2021
23d7fc1
FAIL
miscco Jun 24, 2021
6ff6d9a
Add some optional tests
miscco Jun 24, 2021
5a956d7
Add nullopt tests
miscco Jun 25, 2021
20bdbff
Add variant tests
miscco Jun 25, 2021
d5cd6f5
Avoid UB in variant::_Emplace_valueless
miscco Jun 25, 2021
4268ae0
finx invalid template emplace
miscco Jun 25, 2021
3683d90
Be more consstent with the assignment operator
miscco Jun 25, 2021
43ddb95
Minor cleanups
miscco Jun 25, 2021
d33b6c2
Work around DevCom-1331017
miscco Jun 25, 2021
3c820d7
Do not work with an empty dumy struct
miscco Jun 25, 2021
9a3c126
Merge branch 'main' into P2231-constexpr-optional
miscco Jul 4, 2021
8e7f2ab
Unblock for clang / EDG
miscco Jul 4, 2021
692580f
Minor bugfix
miscco Jul 4, 2021
4a1c79e
Remove workaround as we do not enable the feature for MSVC
miscco Jul 4, 2021
2fe73d6
Fix test
miscco Jul 5, 2021
5a71a67
Merge branch 'main' into P2231-constexpr-optional
miscco Aug 6, 2021
7e7867c
Stealth merge conflict: `_CONSTEXPR20_DYNALLOC` to `_CONSTEXPR20`.
StephanTLavavej Aug 7, 2021
89186b9
`_CONSTEXPR20_VARIANT` => `_CONSTEXPR20` in product code.
StephanTLavavej Aug 7, 2021
4f6046f
Use `constexpr` unconditionally in `P2231R1_complete_constexpr_option…
StephanTLavavej Aug 7, 2021
2a3d31e
Rework feature-test macros.
StephanTLavavej Aug 7, 2021
7b66988
Update `is_literal_type<optional<T>>` test.
StephanTLavavej Aug 7, 2021
cd2b0e0
Update `tests/libcxx/expected_results.txt`.
StephanTLavavej Aug 7, 2021
fa1535d
256 is now too big (32-bit Clang runs out of memory).
StephanTLavavej Aug 7, 2021
aac8599
Disable constexpr optional / variant for MSVC
miscco Aug 8, 2021
a2c4d94
Minor test cleanup
CaseyCarter Aug 9, 2021
4ab846a
s/destrut/destruct/g
CaseyCarter Aug 12, 2021
0d4d285
Update skip lists
CaseyCarter Aug 17, 2021
5e75f52
typo "defaut_constructed"
CaseyCarter Aug 17, 2021
ad71e32
Annotate the bug avoidance conditions with "TRANSITION, FIXME"
CaseyCarter Aug 17, 2021
7bad01b
Localize test failures
CaseyCarter Aug 17, 2021
76dd30e
The bug is, in fact, DevCom-1331017
CaseyCarter Aug 17, 2021
79fbac8
Update tests/std/tests/P2231R1_complete_constexpr_optional_variant/te…
CaseyCarter Aug 17, 2021
5c46fd9
Merge branch 'main' into P2231-constexpr-optional
StephanTLavavej Aug 19, 2021
3024814
Test `optional` construction from different `optional` types.
StephanTLavavej Aug 19, 2021
36b929c
Rename all the things
miscco Aug 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions stl/inc/optional
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct _Optional_destruct_base { // either contains a value of _Ty or is empty (
constexpr explicit _Optional_destruct_base(in_place_t, _Types&&... _Args)
: _Value(_STD forward<_Types>(_Args)...), _Has_value{true} {} // initialize contained value with _Args...

void reset() noexcept {
_CONSTEXPR20 void reset() noexcept {
_Has_value = false;
}
};
Expand All @@ -88,7 +88,7 @@ struct _Optional_destruct_base<_Ty, false> { // either contains a value of _Ty o
};
bool _Has_value;

~_Optional_destruct_base() noexcept {
_CONSTEXPR20 ~_Optional_destruct_base() noexcept {
if (_Has_value) {
_Destroy_in_place(_Value);
}
Expand All @@ -105,7 +105,7 @@ struct _Optional_destruct_base<_Ty, false> { // either contains a value of _Ty o
_Optional_destruct_base& operator=(const _Optional_destruct_base&) = default;
_Optional_destruct_base& operator=(_Optional_destruct_base&&) = default;

void reset() noexcept {
_CONSTEXPR20 void reset() noexcept {
if (_Has_value) {
_Destroy_in_place(_Value);
_Has_value = false;
Expand All @@ -119,15 +119,16 @@ struct _Optional_construct_base : _Optional_destruct_base<_Ty> {
using _Optional_destruct_base<_Ty>::_Optional_destruct_base;

template <class... _Types>
_Ty& _Construct(_Types&&... _Args) { // transition from the empty to the value-containing state
_CONSTEXPR20 _Ty& _Construct(_Types&&... _Args) {
// transition from the empty to the value-containing state
_STL_INTERNAL_CHECK(!this->_Has_value);
_Construct_in_place(this->_Value, _STD forward<_Types>(_Args)...);
this->_Has_value = true;
return this->_Value;
}

template <class _Ty2>
void _Assign(_Ty2&& _Right) { // assign / initialize the contained value from _Right
_CONSTEXPR20 void _Assign(_Ty2&& _Right) { // assign / initialize the contained value from _Right
if (this->_Has_value) {
this->_Value = _STD forward<_Ty2>(_Right);
} else {
Expand All @@ -136,7 +137,7 @@ struct _Optional_construct_base : _Optional_destruct_base<_Ty> {
}

template <class _Self>
void _Construct_from(_Self&& _Right) noexcept(
_CONSTEXPR20 void _Construct_from(_Self&& _Right) noexcept(
is_nothrow_constructible_v<_Ty, decltype((_STD forward<_Self>(_Right)._Value))>) {
// initialize contained value from _Right iff it contains a value
if (_Right._Has_value) {
Expand All @@ -145,7 +146,7 @@ struct _Optional_construct_base : _Optional_destruct_base<_Ty> {
}

template <class _Self>
void _Assign_from(_Self&& _Right) noexcept(
_CONSTEXPR20 void _Assign_from(_Self&& _Right) noexcept(
is_nothrow_constructible_v<_Ty, decltype((_STD forward<_Self>(_Right)._Value))>&&
is_nothrow_assignable_v<_Ty&, decltype((_STD forward<_Self>(_Right)._Value))>) {
// assign/initialize/destroy contained value from _Right
Expand Down Expand Up @@ -208,7 +209,7 @@ public:
#if _HAS_CONDITIONAL_EXPLICIT
template <class _Ty2,
enable_if_t<conjunction_v<_AllowUnwrapping<_Ty2>, is_constructible<_Ty, const _Ty2&>>, int> = 0>
explicit(!is_convertible_v<const _Ty2&, _Ty>) optional(const optional<_Ty2>& _Right) {
_CONSTEXPR20 explicit(!is_convertible_v<const _Ty2&, _Ty>) optional(const optional<_Ty2>& _Right) {
if (_Right) {
this->_Construct(*_Right);
}
Expand All @@ -234,7 +235,7 @@ public:

#if _HAS_CONDITIONAL_EXPLICIT
template <class _Ty2, enable_if_t<conjunction_v<_AllowUnwrapping<_Ty2>, is_constructible<_Ty, _Ty2>>, int> = 0>
explicit(!is_convertible_v<_Ty2, _Ty>) optional(optional<_Ty2>&& _Right) {
_CONSTEXPR20 explicit(!is_convertible_v<_Ty2, _Ty>) optional(optional<_Ty2>&& _Right) {
if (_Right) {
this->_Construct(_STD move(*_Right));
}
Expand All @@ -258,7 +259,7 @@ public:
}
#endif // ^^^ !_HAS_CONDITIONAL_EXPLICIT ^^^

optional& operator=(nullopt_t) noexcept {
_CONSTEXPR20 optional& operator=(nullopt_t) noexcept {
reset();
return *this;
}
Expand All @@ -267,7 +268,7 @@ public:
negation<conjunction<is_scalar<_Ty>, is_same<_Ty, decay_t<_Ty2>>>>,
is_constructible<_Ty, _Ty2>, is_assignable<_Ty&, _Ty2>>,
int> = 0>
optional& operator=(_Ty2&& _Right) {
_CONSTEXPR20 optional& operator=(_Ty2&& _Right) {
this->_Assign(_STD forward<_Ty2>(_Right));
return *this;
}
Expand All @@ -281,7 +282,7 @@ public:
template <class _Ty2, enable_if_t<conjunction_v<_AllowUnwrappingAssignment<_Ty2>,
is_constructible<_Ty, const _Ty2&>, is_assignable<_Ty&, const _Ty2&>>,
int> = 0>
optional& operator=(const optional<_Ty2>& _Right) {
_CONSTEXPR20 optional& operator=(const optional<_Ty2>& _Right) {
if (_Right) {
this->_Assign(*_Right);
} else {
Expand All @@ -294,7 +295,7 @@ public:
template <class _Ty2, enable_if_t<conjunction_v<_AllowUnwrappingAssignment<_Ty2>, is_constructible<_Ty, _Ty2>,
is_assignable<_Ty&, _Ty2>>,
int> = 0>
optional& operator=(optional<_Ty2>&& _Right) {
_CONSTEXPR20 optional& operator=(optional<_Ty2>&& _Right) {
if (_Right) {
this->_Assign(_STD move(*_Right));
} else {
Expand All @@ -305,19 +306,20 @@ public:
}

template <class... _Types>
_Ty& emplace(_Types&&... _Args) {
_CONSTEXPR20 _Ty& emplace(_Types&&... _Args) {
reset();
return this->_Construct(_STD forward<_Types>(_Args)...);
}

template <class _Elem, class... _Types,
enable_if_t<is_constructible_v<_Ty, initializer_list<_Elem>&, _Types...>, int> = 0>
_Ty& emplace(initializer_list<_Elem> _Ilist, _Types&&... _Args) {
_CONSTEXPR20 _Ty& emplace(initializer_list<_Elem> _Ilist, _Types&&... _Args) {
reset();
return this->_Construct(_Ilist, _STD forward<_Types>(_Args)...);
}

void swap(optional& _Right) noexcept(is_nothrow_move_constructible_v<_Ty>&& is_nothrow_swappable_v<_Ty>) {
_CONSTEXPR20 void swap(optional& _Right) noexcept(
is_nothrow_move_constructible_v<_Ty>&& is_nothrow_swappable_v<_Ty>) {
static_assert(is_move_constructible_v<_Ty>,
"optional<T>::swap requires T to be move constructible (N4828 [optional.swap]/1).");
static_assert(!is_move_constructible_v<_Ty> || is_swappable_v<_Ty>,
Expand Down Expand Up @@ -654,7 +656,7 @@ _NODISCARD constexpr compare_three_way_result_t<_Ty1, _Ty2>
#endif // __cpp_lib_concepts

template <class _Ty, enable_if_t<is_move_constructible_v<_Ty> && is_swappable_v<_Ty>, int> = 0>
void swap(optional<_Ty>& _Left, optional<_Ty>& _Right) noexcept(noexcept(_Left.swap(_Right))) {
_CONSTEXPR20 void swap(optional<_Ty>& _Left, optional<_Ty>& _Right) noexcept(noexcept(_Left.swap(_Right))) {
_Left.swap(_Right);
}

Expand Down
Loading