This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofTC1 status.
Section: 27.4.3.7.8[string.swap]Status:TC1Submitter: Jack ReevesOpened: 1997-12-11Last modified: 2016-11-12
Priority:Not Prioritized
View all otherissues in [string.swap].
View all issues withTC1 status.
Duplicate of:87
Discussion:
At the very end of the basic_string class definition is the signature: intcompare(size_type pos1, size_type n1, const charT* s, size_type n2 = npos) const; In thefollowing text this is defined as: returnsbasic_string<charT,traits,Allocator>(*this,pos1,n1).compare(basic_string<charT,traits,Allocator>(s,n2);
Since the constructor basic_string(const charT* s, size_type n, const Allocator& a= Allocator()) clearly requires that s != NULL and n < npos and further states that itthrows length_error if n == npos, it appears the compare() signature above should alwaysthrow length error if invoked like so: str.compare(1, str.size()-1, s); where 's' is somenull terminated character array.
This appears to be a typo since the obvious intent is to allow either the call above orsomething like: str.compare(1, str.size()-1, s, strlen(s)-1);
This would imply that what was really intended was two signatures int compare(size_typepos1, size_type n1, const charT* s) const int compare(size_type pos1, size_type n1, constcharT* s, size_type n2) const; each defined in terms of the corresponding constructor.
Proposed resolution:
Replace the compare signature in 27.4.3[basic.string](at the very end of the basic_string synopsis) which reads:
int compare(size_type pos1, size_type n1,
const charT* s, size_type n2 = npos) const;
with:
int compare(size_type pos1, size_type n1,
const charT* s) const;
int compare(size_type pos1, size_type n1,
const charT* s, size_type n2) const;
Replace the portion of 27.4.3.7.8[string.swap]paragraphs 5 and 6 which read:
int compare(size_type pos, size_type n1,Returns:
charT * s, size_type n2 = npos) const;
basic_string<charT,traits,Allocator>(*this, pos, n1).compare(
basic_string<charT,traits,Allocator>( s, n2))
with:
int compare(size_type pos, size_type n1,Returns:
const charT * s) const;Returns:
basic_string<charT,traits,Allocator>(*this, pos, n1).compare(
basic_string<charT,traits,Allocator>( s ))
int compare(size_type pos, size_type n1,
const charT * s, size_type n2) const;
basic_string<charT,traits,Allocator>(*this, pos, n1).compare(
basic_string<charT,traits,Allocator>( s, n2))
Editors please note that in addition to splitting the signature, the third argumentbecomes const, matching the existing synopsis.
Rationale:
While the LWG dislikes adding signatures, this is a clear defect inthe Standard which must be fixed. The same problem was alsoidentified in issues 7 (item 5) and 87.