Date
2024-12-21.00:00:00
Message id
14530

Content

LWG 3638, which proposes changes to vector<bool>::reference, is related. Should vector<bool>::reference and bitset<N>::reference behave differently in any respect? I think there's no good reason for them to behave differently, and good technical incentives to permit them to behave the same. We already have implementation divergence: libc++ makes `bitset::reference` const-assignable, whereas libstdc++ and MS STL do not. This means that libc++'s `bitset::reference` successfully avoids false positives from Arthur's proposed -Wassign-to-class-rvalue diagnostic, while libstdc++'s does not (See Godbolt).

The proposed resolution applies P2321's approach. We can't just insert `const` into the existing spec, because ABI. But also, since our goal is consistency with the post-P2321 vector<bool>::reference, we should do the same thing here as P2321, not invent anything novel.

Open questions related to the current P/R:

  1. LWG 3638 proposes to add these three `swap` overloads to vector<bool>::reference. Should we also, consistently, add them to `bitset::reference`? I think we should.

    friend constexpr void swap(reference x, reference y) noexcept;
    friend constexpr void swap(reference x, bool& y) noexcept;
    friend constexpr void swap(bool& x, reference y) noexcept;
    
  2. Both vector<bool>::reference and `bitset::reference` right now are specified with

    constexpr reference(const reference&) = default;
    

    which is meaningless because we don't know the data members of `reference`. So this isn't actually specifying that the constructor is trivial, let alone that it's `noexcept`. I think we should re-specify both types' copy constructors as simply `constexpr` and `noexcept`; and then if we want them to be trivial, we should say so in English prose.