Bug #2445
closed
name::Component::compare return value is not guaranteed
Added by Junxiao Shi almost 10 years ago.
Updated over 9 years ago.
Description
name::Component::compare
documentation defines its return value to be either -1, 0, or 1.
Its implementation contains return std::memcmp(...
.
std::memcmp
returns either "negative value", 0, or "positive value", where "negative value" isn't guaranteed to be -1, and "positive value" isn't guaranteed to be 1.
The result would be compiler dependent.
The intended is to convert the return to a if statement converting the result into -1, 0, 1?
- Status changed from New to In Progress
- Assignee set to Joao Pereira
- Status changed from In Progress to Code review
- % Done changed from 0 to 100
What about alternative solution: change documentation. I'm not aware of anybody actually comparing to +/- 1 and just any negative, 0, or any positive value is perfectly fine result for name::Component::compare.
change documentation
The documented behavior can be implemented correctly and efficiently, so there's no reason to loosen requirements.
I disagree. It was an error to define behavior that narrowly in the documentation. An equivalent for this operation (and what this method was modeled against) is std::string::compare
that defines the return value as <0
, 0
, or >0
.
We should fix documentation error, not enforce unnecessarily defined strictness in the docs.
If we decide to loosen the spec to negative/zero/positive, same should apply to Name::compare
, and the last return
in Name::compare
impl could be changed to return count1 - count2;
.
I prefer updating all specs, including Name::compare and anything else that explicitly defines -1
, 0
, and +1
- Status changed from Code review to Feedback
- Target version set to v0.4
@Joao, please rework according to note-10 and note-11.
- Description updated (diff)
- Status changed from Feedback to Closed
Also available in: Atom
PDF