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

720. Omissions in constexpr usages

Section: 24.3.7 [array], 22.9.2 [template.bitset] Status: CD1 Submitter: Daniel Krügler Opened: 2007-08-25 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [array].

View all issues with CD1 status.

Discussion:

  1. The member function bool array<T,N>::empty() const should be a constexpr because this is easily to proof and to implement following it's operational semantics defined by Table 87 (Container requirements) which says: a.size() == 0.
  2. The member function bool bitset<N>::test() const must be a constexpr (otherwise it would violate the specification of constexpr bitset<N>::operator[](size_t) const, because it's return clause delegates to test()).
  3. I wonder how the constructor bitset<N>::bitset(unsigned long) can be declared as a constexpr. Current implementations usually have no such bitset c'tor which would fulfill the requirements of a constexpr c'tor because they have a non-empty c'tor body that typically contains for-loops or memcpy to compute the initialisation. What have I overlooked here?

[ Sophia Antipolis: ]

We handle this as two parts

  1. The proposed resolution is correct; move to ready.
  2. The issue points out a real problem, but the issue is larger than just this solution. We believe a paper is needed, applying the full new features of C++ (including extensible literals) to update std::bitset. We note that we do not consider this new work, and that is should be handled by the Library Working Group.

In order to have a consistent working paper, Alisdair and Daniel produced a new wording for the resolution.

Proposed resolution:

  1. In the class template definition of 24.3.7 [array]/p. 3 change

    constexpr bool empty() const;
    
  2. In the class template definition of 22.9.2 [template.bitset]/p. 1 change

    constexpr bool test(size_t pos ) const;
    

    and in 22.9.2.3 [bitset.members] change

    constexpr bool test(size_t pos ) const;