Movatterモバイル変換


[0]ホーム

URL:



This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofWP status.

4140. Useless default constructors for bit reference types

Section: 22.9.2.1[template.bitset.general], 23.3.14.1[vector.bool.pspc]Status:WPSubmitter: Jonathan WakelyOpened: 2024-08-21Last modified: 2024-11-28

Priority:Not Prioritized

View all otherissues in [template.bitset.general].

View all issues withWP status.

Discussion:

The standard shows a private default constructor forbitset<N>::referencebut does not define its semantics, and nothing in the spec refers to it.It was present in C++98, then in C++11 it gotnoexcept added to it,and in C++23 it was madeconstexpr byP2417R2. That's quitea lot of churn for an unusuable member function with no definition.

In libstdc++ it's declared as private, but never defined.In libc++ it doesn't exist at all.In MSVC it is private and defined (and presumably used somewhere).There's no reason for the standard to declare it.Implementers can define it as private if they want to, or not.The spec doesn't need to say anything for that to be true.We can also remove the friend declaration, because implementers know how todo that too.

I suspect it was added as private originally so that it didn't look likereference should have an implicitly-defined default constructor,which would have been the case in previous standards with no otherconstructors declared.However, C++20 addedreference(const reference&) = default;which suppresses the implicit default constructor, so declaring thedefault constructor as private is now unnecessary.

Jiang An pointed out in an editorial pull request thatvector<bool, Alloc>::referencehas exactly the same issue.

[2024-09-18; Reflector poll]

Set status to Tentatively Ready after eight votes in favour during reflector poll.

[Wrocław 2024-11-23; Status changed: Voting → WP.]

Proposed resolution:

This wording is relative toN4988.

  1. Modify 22.9.2.1[template.bitset.general] as indicated:

    namespace std {  template<size_t N> class bitset {  public:// bit reference    class reference {friend class bitset;constexpr reference() noexcept;    public:      constexpr reference(const reference&) = default;      constexpr ~reference();      constexpr reference& operator=(bool x) noexcept;// for b[i] = x;      constexpr reference& operator=(const reference&) noexcept;// for b[i] = b[j];      constexpr bool operator~() const noexcept;// flips the bit      constexpr operator bool() const noexcept;// for x = b[i];      constexpr reference& flip() noexcept;// for b[i].flip();    };
  2. Modify 23.3.14.1[vector.bool.pspc],vector<bool, Allocator> synopsis, as indicated:

    namespace std {  template<class Allocator>  class vector<bool, Allocator> {  public:// types    […]// bit reference    class reference {friend class vector;constexpr reference() noexcept;    public:      constexpr reference(const reference&) = default;      constexpr ~reference();      constexpr operator bool() const noexcept;      constexpr reference& operator=(bool x) noexcept;      constexpr reference& operator=(const reference& x) noexcept;      constexpr const reference& operator=(bool x) const noexcept;      constexpr void flip() noexcept;// flips the bit    };

[8]ページ先頭

©2009-2026 Movatter.jp