This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++11 status.
Section: 22.9.2.3[bitset.members]Status:C++11Submitter: Daniel KrüglerOpened: 2008-09-26Last modified: 2016-01-28
Priority:Not Prioritized
View all otherissues in [bitset.members].
View all issues withC++11 status.
Discussion:
The current standard 14882::2003(E) as well as the current draftN2723have in common a contradiction of the operational semantics of member functiontest 22.9.2.3[bitset.members] p.56-58 and the immutablememberoperator[] overload 22.9.2.3[bitset.members] p.64-66 (all referencesare defined in terms ofN2723):
bool test(size_t pos) const;
Requires:
posis validThrows:
out_of_rangeifposdoes not correspondto a valid bit position.Returns:
trueif the bit at positionposin*thishas the value one.
constexpr bool operator[](size_t pos) const;
Requires:
posshall be valid.Throws: nothing.
Returns:
test(pos).
Three interpretations:
operator[] overload is indeed allowed to throw an exception(viatest(), ifpos corresponds to an invalid bit position) which doesnot leave the call frame. In this case this function cannot be aconstexpr function, becausetest() is not, due to7.7[expr.const]/2, last bullet.test in case of aninvalid bit position. There is only little evidence for this interpretation.operator[] should not throw any exception,but thattest has the contract to do so, if the provided bit positionis invalid.The problem became worse, because issue720(i)recently voted into WP argued that membertest logically must beaconstexpr function, because it was used to define the semanticsof anotherconstexpr function (theoperator[] overload).
Three alternatives are proposed, corresponding to the three bullets(A), (B), and (C), the author suggests to follow proposal (C).
Proposed alternatives:
Remove theconstexpr specifier in front ofoperator[] overload andundo that of membertest (assuming720(i) is accepted) in both theclass declaration 22.9.2[template.bitset]/1 and in the member descriptionbefore 22.9.2.3[bitset.members]/56 and before /64 to read:
constexprbool test(size_t pos) const;..constexprbool operator[](size_t pos) const;
Change the throws clause of p. 65 to read:
Throws:
nothingout_of_rangeifposdoes not correspond to a valid bitposition.
Replace the throws clause p. 57 to read:
Throws:
nothing.out_of_rangeifposdoes not correspond to a valid bitposition
Undo the addition of theconstexpr specifier to thetest memberfunction in both class declaration 22.9.2[template.bitset]/1 and in themember description before 22.9.2.3[bitset.members]/56, assuming that720(i)was applied.
constexprbool test(size_t pos) const;
Change the returns clause p. 66 to read:
Returns:
test(pos)trueif the bit at positionposin*thishas the value one, otherwisefalse.
[Post Summit:]
Lawrence: proposed resolutions A, B, C are mutually exclusive.
Recommend Review with option C.
[Batavia (2009-05):]
We agree with the proposed resolution.Move to Tentatively Ready.
Proposed resolution:
Undo the addition of theconstexpr specifier to thetest memberfunction in both class declaration 22.9.2[template.bitset] p.1 and in themember description before 22.9.2.3[bitset.members] p.56, assuming that720(i)was applied.
constexprbool test(size_t pos) const;
Change the returns clause p. 66 to read:
Returns:
test(pos)trueif the bit at positionposin*thishas the value one, otherwisefalse.