diff --git a/libstdc++-v3/include/bits/funcwrap.h b/libstdc++-v3/include/bits/funcwrap.h index 9db4ab7811a..70ecfd93e36 100644 --- a/libstdc++-v3/include/bits/funcwrap.h +++ b/libstdc++-v3/include/bits/funcwrap.h @@ -419,6 +419,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _M_manage = _Manager::_S_empty; } + void _M_destroy() noexcept + { _M_manage(_Manager::_Op::_Destroy, _M_storage, nullptr); } + ~_Mo_base() { _M_destroy(); } @@ -434,17 +437,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION std::swap(_M_manage, __x._M_manage); } - _Storage _M_storage; - - private: - void _M_destroy() noexcept - { _M_manage(_Manager::_Op::_Destroy, _M_storage, nullptr); } - _Manager::_Func _M_manage; - -#ifdef __glibcxx_copyable_function // C++ >= 26 && HOSTED - friend class _Cpy_base; -#endif // __glibcxx_copyable_function + _Storage _M_storage; }; #endif // __glibcxx_copyable_function || __glibcxx_copyable_function } // namespace __polyfunc diff --git a/libstdc++-v3/testsuite/20_util/copyable_function/call.cc b/libstdc++-v3/testsuite/20_util/copyable_function/call.cc index 0ac5348f2fe..605422d5595 100644 --- a/libstdc++-v3/testsuite/20_util/copyable_function/call.cc +++ b/libstdc++-v3/testsuite/20_util/copyable_function/call.cc @@ -214,6 +214,28 @@ test_params() std::copyable_function f4; } +struct EmptyIdFunc +{ + EmptyIdFunc* operator()() + { return this; } +}; + +struct Composed : EmptyIdFunc +{ + std::move_only_function nested; +}; + +void +test_aliasing() +{ + Composed c; + c.nested = EmptyIdFunc{}; + + EmptyIdFunc* baseAddr = c(); + EmptyIdFunc* nestedAddr = c.nested(); + VERIFY( baseAddr != nestedAddr ); +}; + int main() { test01(); @@ -222,4 +244,5 @@ int main() test04(); test05(); test_params(); + test_aliasing(); } diff --git a/libstdc++-v3/testsuite/20_util/move_only_function/call.cc b/libstdc++-v3/testsuite/20_util/move_only_function/call.cc index 72c8118d716..34ca73b4eb4 100644 --- a/libstdc++-v3/testsuite/20_util/move_only_function/call.cc +++ b/libstdc++-v3/testsuite/20_util/move_only_function/call.cc @@ -214,6 +214,28 @@ test_params() std::move_only_function f4; } +struct EmptyIdFunc +{ + EmptyIdFunc* operator()() + { return this; } +}; + +struct Composed : EmptyIdFunc +{ + std::move_only_function nested; +}; + +void +test_aliasing() +{ + Composed c; + c.nested = EmptyIdFunc{}; + + EmptyIdFunc* baseAddr = c(); + EmptyIdFunc* nestedAddr = c.nested(); + VERIFY( baseAddr != nestedAddr ); +}; + int main() { test01(); @@ -222,4 +244,5 @@ int main() test04(); test05(); test_params(); + test_aliasing(); }