isocpp / isocpp/CppCoreGuidelines
I.7: State postconditions - undefined behavior in first "consider using"
Open
@gdr-at-ms is already working on this.
Since Oct 10, 2016.
waiting
- Dominant language
- CSS
- Stars
- 45.3k
- Forks
- 5.6k
- PR merge metrics
- No merged PRs in 30d
Description
The solution to the first example is:
int area(int height, int width)
{
auto res = height*width;
Ensures(res>0);
return res;
}
When the multiplication overflows, undefined behavior is invoked. This makes the Ensures(res>0) depend on undefined behavior.
I'm not sure what the correct solution should be like. Possibly something like clang's and gcc's __builtin_sadd_overflow or one of the techniques described in the book Hacker's Delight. The former would be clang/gcc-specific, the latter quite involved.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.