Addressed PR #140.

This commit is contained in:
hsutter 2015-12-29 10:15:43 -08:00
parent c9e015ce1f
commit 10d1d9dbc5

View File

@ -6424,7 +6424,7 @@ Enumeration rule summary:
##### Reason ##### Reason
Macros do not obey scope and type rules. Macros do not obey scope and type rules. Also, macro names are removed during preprocessing and so usually don't appear in tools like debuggers.
##### Example ##### Example
@ -9326,17 +9326,31 @@ The result is undefined and probably a crash.
##### Note ##### Note
this also applies to `%`. This also applies to `%`.
##### Example ##### Example; bad
??? double divide(int a, int b) {
return a/b; // BAD, should be checked (e.g., in a precondition)
}
##### Example; good
double divide(int a, int b) {
Expects(b != 0); // good, address via precondition (and replace with contracts once C++ gets them)
return a/b;
}
double divide(int a, int b) {
return b ? a/b : quiet_NaN<double>(); // good, address via check
}
**Alternative**: For critical applications that can afford some overhead, use a range-checked integer and/or floating-point type. **Alternative**: For critical applications that can afford some overhead, use a range-checked integer and/or floating-point type.
##### Enforcement ##### Enforcement
??? * Flag division by an integral value that could be zero
# <a name="S-performance"></a> PER: Performance # <a name="S-performance"></a> PER: Performance