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

Implement LWG-3146: Excessive unwrapping in std::ref/cref #2409

Merged
merged 3 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions stl/inc/type_traits
Original file line number Diff line number Diff line change
Expand Up @@ -1842,7 +1842,7 @@ void ref(const _Ty&&) = delete;

template <class _Ty>
_NODISCARD _CONSTEXPR20 reference_wrapper<_Ty> ref(reference_wrapper<_Ty> _Val) noexcept {
return _STD ref(_Val.get());
return _Val;
}

template <class _Ty>
Expand All @@ -1855,7 +1855,7 @@ void cref(const _Ty&&) = delete;

template <class _Ty>
_NODISCARD _CONSTEXPR20 reference_wrapper<const _Ty> cref(reference_wrapper<_Ty> _Val) noexcept {
return _STD cref(_Val.get());
return _Val;
}

#if _HAS_CXX20
Expand Down
13 changes: 13 additions & 0 deletions tests/tr1/tests/functional9/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ static void t_invoke() { // test invoke
CHECK_INT(STD invoke(sum4, 1, 3, 5, 7), 16);
}

// COMPILE-ONLY
fsb4000 marked this conversation as resolved.
Show resolved Hide resolved
void test_LWG_3146() {
int i = 0;
STD reference_wrapper<int> ri(i);
STD reference_wrapper<STD reference_wrapper<int>> rri(ri);
fsb4000 marked this conversation as resolved.
Show resolved Hide resolved

auto reference = STD ref(rri);
auto const_reference = STD cref(rri);

(void) reference;
fsb4000 marked this conversation as resolved.
Show resolved Hide resolved
(void) const_reference;
}

void test_main() { // test header <functional>
// reference_wrapper::operator() with rvalues
call1(STD cref(fake_lvalue(&f1)));
Expand Down