Skip to content

Commit

Permalink
Make optional's secret constructor private (microsoft#4961)
Browse files Browse the repository at this point in the history
  • Loading branch information
CaseyCarter committed Sep 19, 2024
1 parent 397901c commit 7b154c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
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

0 comments on commit 7b154c5

Please sign in to comment.