Skip to content

<array>: array<const T, 0> allows fill() and swap() #1295

Description

Similar-but-distinct from #942; we should track it as a separate issue. The following libcxx tests are skipped:

# STL bug: We allow fill() and swap() for array<const T, 0>.
std/containers/sequences/array/array.fill/fill.fail.cpp FAIL
std/containers/sequences/array/array.swap/swap.fail.cpp FAIL

# STL bug: We allow fill() and swap() for array<const T, 0>.
containers\sequences\array\array.fill\fill.fail.cpp
containers\sequences\array\array.swap\swap.fail.cpp

Because they're implemented as no-ops:

STL/stl/inc/array

Lines 600 to 622 in 9e76d8c

template <class _Ty>
class array<_Ty, 0> {
public:
using value_type = _Ty;
using size_type = size_t;
using difference_type = ptrdiff_t;
using pointer = _Ty*;
using const_pointer = const _Ty*;
using reference = _Ty&;
using const_reference = const _Ty&;
using iterator = _Array_iterator<_Ty, 0>;
using const_iterator = _Array_const_iterator<_Ty, 0>;
using reverse_iterator = _STD reverse_iterator<iterator>;
using const_reverse_iterator = _STD reverse_iterator<const_iterator>;
#if _HAS_TR1_NAMESPACE
_DEPRECATE_TR1_NAMESPACE void assign(const _Ty&) {}
#endif // _HAS_TR1_NAMESPACE
_CONSTEXPR20 void fill(const _Ty&) {}
_CONSTEXPR20 void swap(array&) noexcept {}

WG21-N4861 [array.members]/3 specifies fill() with "Effects: As if by fill_n(begin(), N, u)." and /4 specifies swap() with "Effects: Equivalent to swap_ranges(begin(), end(), y.begin())."

Notably, these "equivalent to" calls are ill-formed for const T (even if there happen to be zero of them), so libcxx is correct to expect these to fail to compile (this is what meow.fail.cpp means).

We should be able to fix this without breaking ABI; static_assert should be sufficient.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    LWG issue neededA wording defect that should be submitted to LWG as a new issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions