Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make optional's secret constructor private #4961

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 10 additions & 7 deletions stl/inc/optional
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ class optional : private _SMF_control<_Optional_construct_base<_Ty>, _Ty> {
private:
using _Mybase = _SMF_control<_Optional_construct_base<_Ty>, _Ty>;

template <class>
friend class optional;

#if _HAS_CXX23
template <class _Fn, class _Ux>
constexpr optional(_Construct_from_invoke_result_tag _Tag, _Fn&& _Func, _Ux&& _Arg)
noexcept(noexcept(static_cast<_Ty>(_STD invoke(_STD forward<_Fn>(_Func), _STD forward<_Ux>(_Arg)))))
: _Mybase(_Tag, _STD forward<_Fn>(_Func), _STD forward<_Ux>(_Arg)) {}
#endif // _HAS_CXX23

public:
static_assert(!_Is_any_of_v<remove_cv_t<_Ty>, nullopt_t, in_place_t>,
"T in optional<T> must be a type other than nullopt_t or in_place_t (N4950 [optional.optional.general]/3).");
Expand Down Expand Up @@ -273,13 +283,6 @@ public:
}
}

#if _HAS_CXX23
template <class _Fn, class _Ux>
constexpr optional(_Construct_from_invoke_result_tag _Tag, _Fn&& _Func, _Ux&& _Arg)
noexcept(noexcept(static_cast<_Ty>(_STD invoke(_STD forward<_Fn>(_Func), _STD forward<_Ux>(_Arg)))))
: _Mybase(_Tag, _STD forward<_Fn>(_Func), _STD forward<_Ux>(_Arg)) {}
#endif // _HAS_CXX23

_CONSTEXPR20 optional& operator=(nullopt_t) noexcept {
reset();
return *this;
Expand Down
3 changes: 0 additions & 3 deletions tests/libcxx/expected_results.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1225,9 +1225,6 @@ std/numerics/c.math/hermite.pass.cpp FAIL
# Not analyzed. Test coverage for LLVM-104496 uses span<Incomplete>.
std/containers/views/views.span/span.cons/copy.pass.cpp FAIL

# Not analyzed. LLVM-103409 added a test to verify that std::optional's internal constructors aren't visible to users.
std/utilities/optional/optional.object/optional.object.ctor/gh_101960_internal_ctor.compile.pass.cpp FAIL


# *** XFAILS WHICH PASS ***
# These tests contain `// XFAIL: msvc` comments, which accurately describe runtime failures for x86 and x64.
Expand Down