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

std::forward_list::swap noexcept specification not using correct member type #49568

Closed
llvmbot opened this issue May 5, 2021 · 1 comment
Closed
Labels
bugzilla Issues migrated from bugzilla libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@llvmbot
Copy link
Member

llvmbot commented May 5, 2021

Bugzilla Link 50224
Resolution FIXED
Resolved on Jun 22, 2021 09:42
Version 12.0
OS Linux
Reporter LLVM Bugzilla Contributor
CC @ldionne,@mclow
Fixed by commit(s) 7adf713

Extended Description

The current implementation of std::forward_list::swap is as follows:

_LIBCPP_INLINE_VISIBILITY
    void swap(__forward_list_base& __x)
#if _LIBCPP_STD_VER >= 14
        _NOEXCEPT;
#else
        _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value ||
                    __is_nothrow_swappable<__node_allocator>::value);

which uses propagate_on_container_move_assignment for noexcept specification.

This must use propagate_on_container_swap for checking according to [container.requirements.general/8].

When the change is applied, the declaration should look like:

_LIBCPP_INLINE_VISIBILITY
    void swap(__forward_list_base& __x)
#if _LIBCPP_STD_VER >= 14
        _NOEXCEPT;
#else
        _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
                    __is_nothrow_swappable<__node_allocator>::value);

and the definition should be as follows:

template <class _Tp, class _Alloc>
inline
void
__forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x)
#if _LIBCPP_STD_VER >= 14
        _NOEXCEPT
#else
        _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
                    __is_nothrow_swappable<__node_allocator>::value)
#endif
{
    _VSTD::__swap_allocator(__alloc(), __x.__alloc(),
            integral_constant<bool, __node_traits::propagate_on_container_swap::value>());
    using _VSTD::swap;
    swap(__before_begin()->__next_, __x.__before_begin()->__next_);
}
@ldionne
Copy link
Member

ldionne commented Jun 22, 2021

Thanks for the fix!

commit 7adf713
Author: Hyundeok Park p.hyundeok76@gmail.com
Date: Tue Jun 22 12:37:51 2021 -0400

[libc++] Change forward_list::swap to use propagate_on_container_swap for noexcept specification

The current implementation of `std::forward_list::swap` uses
`propagate_on_container_move_assignment` for `noexcept` specification.
This patch changes it to use `propagate_on_container_swap`, as it should.

Fixes llvm/llvm-project#49568 .

Differential Revision: https://reviews.llvm.org/D101899

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

2 participants