This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++17 status.
Section: 22.9.2.2 [bitset.cons], 22.9.2.3 [bitset.members], 23.4.3.3 [string.cons], 23.4.3.7 [string.modifiers], 23.4.3.8 [string.ops] Status: C++17 Submitter: Frank Birbacher Opened: 2013-04-18 Last modified: 2017-07-30
Priority: 3
View all other issues in [bitset.cons].
View all issues with C++17 status.
Discussion:
Similar to LWG 2207(i) there are several other places where the "Requires" clause precludes the "Throws" condition.
Searching for the out_of_range
exception to be thrown, the following have been found (based on the working draft
N3485):
22.9.2.2 [bitset.cons] p3+4
22.9.2.3 [bitset.members] p13+14 (set
)
22.9.2.3 [bitset.members] p19+20 (reset
)
22.9.2.3 [bitset.members] p27+28 (flip
)
22.9.2.3 [bitset.members] p41+42 (test
)
23.4.3.3 [string.cons] p3+4
23.4.3.7.2 [string.append] p3+4
23.4.3.7.3 [string.assign] p4+5
23.4.3.7.4 [string.insert] p1+2, p5+6, p9+10 (partially)
23.4.3.7.5 [string.erase] p1+2
23.4.3.7.6 [string.replace] p1+2, p5+6, p9+10 (partially)
23.4.3.7.7 [string.copy] p1+2
23.4.3.8.3 [string.substr] p1+2
[2013-10-15: Daniel provides wording]
In addition to the examples mentioned in the discussion, a similar defect exists for thread
's join()
and detach
functions (see 33.4.3.6 [thread.thread.member]). The suggested wording applies a similar fix for these
as well.
[2015-05, Lenexa]
STL : likes it
DK : does it change behavior?
Multiple : no
Move to ready? Unanimous
Proposed resolution:
This wording is relative to N3936.
Modify 22.9.2.2 [bitset.cons] as indicated: [Editorial comment: The wording form used to ammend the Throws element is borrowed from a similar style used in 23.4.3.7.6 [string.replace] p10]
template <class charT, class traits, class Allocator> explicit bitset(const basic_string<charT, traits, Allocator>& str, typename basic_string<charT, traits, Allocator>::size_type pos = 0, typename basic_string<charT, traits, Allocator>::size_type n = basic_string<charT, traits, Allocator>::npos, charT zero = charT('0'), charT one = charT('1'));-4- Throws:
-3- Requires:pos <= str.size()
.out_of_range
ifpos > str.size()
orinvalid_argument
if an invalid character is found (see below). -5- Effects: Determines the effective lengthrlen
of the initializing string as the smaller ofn
andstr.size() - pos
. The function then throwsinvalid_argument
if any of therlen
characters instr
beginning at positionpos
is other thanzero
orone
. The function usestraits::eq()
to compare the character values. […]
Modify 22.9.2.3 [bitset.members] as indicated:
bitset<N>& set(size_t pos, bool val = true);-14- Throws:
-13- Requires:pos
is validout_of_range
ifpos
does not correspond to a valid bit position. […]
bitset<N>& reset(size_t pos);-20- Throws:
-19- Requires:pos
is validout_of_range
ifpos
does not correspond to a valid bit position. […]
bitset<N>& flip(size_t pos);-28- Throws:
-27- Requires:pos
is validout_of_range
ifpos
does not correspond to a valid bit position. […]
bool test(size_t pos) const;-42- Throws:
-41- Requires:pos
is validout_of_range
ifpos
does not correspond to a valid bit position. […]
Modify 23.4.3.3 [string.cons] as indicated:
basic_string(const basic_string& str, size_type pos, size_type n = npos, const Allocator& a = Allocator());-4- Throws:
-3- Requires:pos <= str.size()
out_of_range
ifpos > str.size()
.
Modify 23.4.3.5 [string.capacity] as indicated:
void resize(size_type n, charT c);-7- Throws:
-6- Requires:n <= max_size()
length_error
ifn > max_size()
.
Modify 23.4.3.7.2 [string.append] as indicated:
basic_string& append(const basic_string& str, size_type pos, size_type n = npos);-4- Throws:
-3- Requires:pos <= str.size()
out_of_range
ifpos > str.size()
.
Modify 23.4.3.7.3 [string.assign] as indicated:
basic_string& assign(const basic_string& str, size_type pos, size_type n = npos);-6- Throws:
-5- Requires:pos <= str.size()
out_of_range
ifpos > str.size()
.
Modify 23.4.3.7.4 [string.insert] as indicated: [Editorial note: The first change suggestion is also a bug fix
of the current wording, because (a) the function has parameter pos1
but the semantics refers to pos
and (b)
it is possible that this function can throw length_error
, see p10]
basic_string& insert(size_type pos1, const basic_string& str);
-1- Requires:pos <= size()
.-2- Throws:-3- Effects:out_of_range
ifpos > size()
.CallsEquivalent to:return insert(pos, str.data(), str.size());
.-4- Returns:*this
.
basic_string& insert(size_type pos1, const basic_string& str, size_type pos2, size_type n = npos);-6- Throws:
-5- Requires:pos1 <= size()
andpos2 <= str.size()
.out_of_range
ifpos1 > size()
orpos2 > str.size()
. […]
basic_string& insert(size_type pos, const charT* s, size_type n);-9- Requires:
-10- Throws:s
points to an array of at leastn
elements ofcharT
and.pos <= size()
out_of_range
ifpos > size()
orlength_error
ifsize() + n > max_size()
. […]
basic_string& insert(size_type pos, const charT* s);-13- Requires:
-14- Effects: Equivalent topos <= size()
ands
points to an array of at leasttraits::length(s) + 1
elements ofcharT
.return insert(pos, s, traits::length(s));
.-15- Returns:*this
.
Modify 23.4.3.7.5 [string.erase] as indicated:
basic_string& erase(size_type pos = 0, size_type n = npos);-2- Throws:
-1- Requires:pos <= size()
out_of_range
ifpos > size()
. […]
Modify 23.4.3.7.6 [string.replace] as indicated: [Editorial note: The first change suggestion is also a bug fix
of the current wording, because it is possible that this function can throw length_error
, see p10]
basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
-1- Requires:pos1 <= size()
.-2- Throws:-3- Effects:out_of_range
ifpos1 > size()
.CallsEquivalent toreturn replace(pos1, n1, str.data(), str.size());
.-4- Returns:*this
.
basic_string& replace(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n = npos);-6- Throws:
-5- Requires:pos1 <= size()
andpos2 <= str.size()
.out_of_range
ifpos1 > size()
orpos2 > str.size()
. […]
basic_string& replace(size_type pos1, size_type n1, const charT* s, size_type n2);-9- Requires:
-10- Throws:pos1 <= size()
ands
points to an array of at leastn2
elements ofcharT
.out_of_range
ifpos1 > size()
orlength_error
if the length of the resulting string would exceedmax_size()
(see below). […]
basic_string& replace(size_type pos, size_type n, const charT* s);-13- Requires:
-14- Effects: Equivalent topos <= size()
ands
points to an array of at leasttraits::length(s) + 1
elements ofcharT
.return replace(pos, n, s, traits::length(s));
.-15- Returns:*this
.
Modify 23.4.3.7.7 [string.copy] as indicated:
size_type copy(charT* s, size_type n, size_type pos = 0) const;-2- Throws:
-1- Requires:pos <= size()
out_of_range
ifpos > size()
. […]
Modify 23.4.3.8.3 [string.substr] as indicated:
basic_string substr(size_type pos = 0, size_type n = npos) const;-2- Throws:
-1- Requires:pos <= size()
out_of_range
ifpos > size()
. […]
Modify 33.4.3.6 [thread.thread.member] as indicated:
void join();[…] -7- Throws:
-3- Requires:joinable()
is true.system_error
when an exception is required (30.2.2). -8- Error conditions:
[…]
invalid_argument
— if the thread is not joinable.
void detach();[…] -12- Throws:
-9- Requires:joinable()
is true.system_error
when an exception is required (30.2.2). -13- Error conditions:
[…]
invalid_argument
— if the thread is not joinable.