Skip to content

Commit adb80d8

Browse files
authored
[libc++] Address post-commit comments for __scope_guard (#116291)
Fixes #116204
1 parent e2b4a70 commit adb80d8

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

libcxx/include/__utility/scope_guard.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,22 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2626
template <class _Func>
2727
class __scope_guard {
2828
_Func __func_;
29-
bool __moved_from_;
3029

3130
public:
32-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __scope_guard(_Func __func) : __func_(std::move(__func)) {}
31+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __scope_guard(_Func __func) : __func_(std::move(__func)) {}
3332
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~__scope_guard() { __func_(); }
3433

35-
__scope_guard(const __scope_guard&) = delete;
34+
__scope_guard(const __scope_guard&) = delete;
35+
__scope_guard& operator=(const __scope_guard&) = delete;
36+
__scope_guard& operator=(__scope_guard&&) = delete;
3637

37-
// C++17 has mandatory RVO, so we don't need the move constructor anymore to make __make_scope_guard work.
38+
// C++14 doesn't have mandatory RVO, so we have to provide a declaration even though no compiler will ever generate
39+
// a call to the move constructor.
3840
#if _LIBCPP_STD_VER <= 14
39-
__scope_guard(__scope_guard&& __other) : __func_(__other.__func_) {
40-
_LIBCPP_ASSERT_INTERNAL(!__other.__moved_from_, "Cannot move twice from __scope_guard");
41-
__other.__moved_from_ = true;
42-
}
41+
__scope_guard(__scope_guard&&);
4342
#else
4443
__scope_guard(__scope_guard&&) = delete;
4544
#endif
46-
47-
__scope_guard& operator=(const __scope_guard&) = delete;
48-
__scope_guard& operator=(__scope_guard&&) = delete;
4945
};
5046

5147
template <class _Func>

0 commit comments

Comments
 (0)