Skip to content

Commit

Permalink
ES.23: change example code to better match the rule
Browse files Browse the repository at this point in the history
The example suggests that `int z = gsl::narrow_cast<int>(7.9);;` is OK. The rule says "Use `=` only when you are sure that there can be no narrowing conversions.", which matches, but is also says "For built-in arithmetic types, use `=` only with `auto`.", and this is not respected here. So replace the one line with both possibilities suggested by the rule.
  • Loading branch information
Werner Henze committed Oct 12, 2023
1 parent 27e662b commit 7569ae7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CppCoreGuidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -11093,7 +11093,8 @@ For containers, there is a tradition for using `{...}` for a list of elements an

int x {7.9}; // error: narrowing
int y = 7.9; // OK: y becomes 7. Hope for a compiler warning
int z = gsl::narrow_cast<int>(7.9); // OK: you asked for it
int z {gsl::narrow_cast<int>(7.9)}; // OK: you asked for it
auto zz = gsl::narrow_cast<int>(7.9); // OK: you asked for it

##### Note

Expand Down

0 comments on commit 7569ae7

Please sign in to comment.