diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 2943a40..94f20bb 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -11602,7 +11602,8 @@ Surprised? I'm just glad I didn't crash the program. ##### Note -Programmer who write casts typically assumes that they know what they are doing. +Programmers who write casts typically assume that they know what they are doing, +or that writing a cast makes the program "easier to read". In fact, they often disable the general rules for using values. Overload resolution and template instantiation usually pick the right function if there is a right function to pick. If there is not, maybe there ought to be, rather than applying a local fix (cast). @@ -11623,16 +11624,14 @@ Casts are widely (mis) used. Modern C++ has constructs that eliminate the need f * Use templates * Use `std::variant` - +* Rely on the well defined, safe, implicit conversions between pointer types ##### Enforcement * Force the elimination of C-style casts -* Warn against named casts -* Warn against unnecessary casts. * Warn if there are many functional style casts (there is an obvious problem in quantifying 'many'). * The [type profile](#Pro-type-reinterpretcast) bans `reinterpret_cast`. - +* Warn against [unnecessary pointer casts](#Pro-type-unnecessarycast). ### ES.49: If you must use a cast, use a named cast @@ -11694,6 +11693,7 @@ for example.) * Flag C-style and functional casts. * The [type profile](#Pro-type-reinterpretcast) bans `reinterpret_cast`. +* The [type profile](#Pro-type-arithmeticcast) warns when using `static_cast` between arithmetic types. ### ES.50: Don't cast away `const` @@ -19399,8 +19399,10 @@ An implementation of this profile shall recognize the following patterns in sour Type safety profile summary: -* Type.1: Don't use `reinterpret_cast`: -A strict version of [Avoid casts](#Res-casts) and [prefer named casts](#Res-casts-named). +* Type.1: [Avoid casts](#Res-casts): + * Don't use `reinterpret_cast`; A strict version of [Avoid casts](#Res-casts) and [prefer named casts](#Res-casts-named). + * Don't a `static_cast` for arithmetic types; A strict version of [Avoid casts](#Res-casts) and [prefer named casts](#Res-casts-named). + * Don't use pointer unnecessary pointer casts; A strict version of [Avoid casts](#Res-casts) * Type.2: Don't use `static_cast` to downcast: [Use `dynamic_cast` instead](#Rh-dynamic_cast). * Type.3: Don't use `const_cast` to cast away `const` (i.e., at all):