From 8789617b239c965b70b3c807c83e2d3bf6a6df8f Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Tue, 9 Jan 2024 05:51:31 +0100 Subject: [PATCH] ES.87 (redundant `==` or `!=`) Fix dynamic_cast to Circle pointer (#2168) The second ES.87 example seemed to mistakenly assume that `Circle` is pointer type, by the way it was using `dynamic_cast`. However, `Circle` is meant to be a class type instead. This fix is consistent with other examples, that also do `dynamic_cast`. --- CppCoreGuidelines.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index ff7f72b14..d1820a32e 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -13335,9 +13335,9 @@ whereas `if (p != nullptr)` would be a long-winded workaround. This rule is especially useful when a declaration is used as a condition - if (auto pc = dynamic_cast(ps)) { ... } // execute if ps points to a kind of Circle, good + if (auto pc = dynamic_cast(ps)) { ... } // execute if ps points to a kind of Circle, good - if (auto pc = dynamic_cast(ps); pc != nullptr) { ... } // not recommended + if (auto pc = dynamic_cast(ps); pc != nullptr) { ... } // not recommended ##### Example