From 2d87c45e4b4003282cbfdcf0f7474423814f87a0 Mon Sep 17 00:00:00 2001 From: Werner Henze <34543625+beinhaerter@users.noreply.github.com> Date: Thu, 12 Oct 2023 21:25:52 +0200 Subject: [PATCH] ES.23: change example code to better match the rule (#2150) The example suggests that `int z = gsl::narrow_cast(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 --- CppCoreGuidelines.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 1ab841f..f0e7aa4 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -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 y = 7.9; // OK: y becomes 7. Hope for a compiler warning - int z = gsl::narrow_cast(7.9); // OK: you asked for it + int z {gsl::narrow_cast(7.9)}; // OK: you asked for it + auto zz = gsl::narrow_cast(7.9); // OK: you asked for it ##### Note