mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
ES.23: change example code to better match the rule (#2150)
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. Co-authored-by: Werner Henze <w.henze@avm.de>
This commit is contained in:
parent
a43285d95a
commit
2d87c45e4b
|
@ -11095,7 +11095,8 @@ For containers, there is a tradition for using `{...}` for a list of elements an
|
||||||
|
|
||||||
int x {7.9}; // error: narrowing
|
int x {7.9}; // error: narrowing
|
||||||
int y = 7.9; // OK: y becomes 7. Hope for a compiler warning
|
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
|
##### Note
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user