Skip to content

Commit 7b154c5

Browse files
authored
Make optional's secret constructor private (#4961)
1 parent 397901c commit 7b154c5

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

stl/inc/optional

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,16 @@ class optional : private _SMF_control<_Optional_construct_base<_Ty>, _Ty> {
214214
private:
215215
using _Mybase = _SMF_control<_Optional_construct_base<_Ty>, _Ty>;
216216

217+
template <class>
218+
friend class optional;
219+
220+
#if _HAS_CXX23
221+
template <class _Fn, class _Ux>
222+
constexpr optional(_Construct_from_invoke_result_tag _Tag, _Fn&& _Func, _Ux&& _Arg)
223+
noexcept(noexcept(static_cast<_Ty>(_STD invoke(_STD forward<_Fn>(_Func), _STD forward<_Ux>(_Arg)))))
224+
: _Mybase(_Tag, _STD forward<_Fn>(_Func), _STD forward<_Ux>(_Arg)) {}
225+
#endif // _HAS_CXX23
226+
217227
public:
218228
static_assert(!_Is_any_of_v<remove_cv_t<_Ty>, nullopt_t, in_place_t>,
219229
"T in optional<T> must be a type other than nullopt_t or in_place_t (N4950 [optional.optional.general]/3).");
@@ -273,13 +283,6 @@ public:
273283
}
274284
}
275285

276-
#if _HAS_CXX23
277-
template <class _Fn, class _Ux>
278-
constexpr optional(_Construct_from_invoke_result_tag _Tag, _Fn&& _Func, _Ux&& _Arg)
279-
noexcept(noexcept(static_cast<_Ty>(_STD invoke(_STD forward<_Fn>(_Func), _STD forward<_Ux>(_Arg)))))
280-
: _Mybase(_Tag, _STD forward<_Fn>(_Func), _STD forward<_Ux>(_Arg)) {}
281-
#endif // _HAS_CXX23
282-
283286
_CONSTEXPR20 optional& operator=(nullopt_t) noexcept {
284287
reset();
285288
return *this;

tests/libcxx/expected_results.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,9 +1225,6 @@ std/numerics/c.math/hermite.pass.cpp FAIL
12251225
# Not analyzed. Test coverage for LLVM-104496 uses span<Incomplete>.
12261226
std/containers/views/views.span/span.cons/copy.pass.cpp FAIL
12271227

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

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

0 commit comments

Comments
 (0)