Skip to content

Commit

Permalink
ES.87 (redundant == or !=) Fix dynamic_cast to Circle pointer (is…
Browse files Browse the repository at this point in the history
…ocpp#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<Circle*>`.
  • Loading branch information
N-Dekker authored Jan 9, 2024
1 parent e49158a commit 8789617
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CppCoreGuidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Circle>(ps)) { ... } // execute if ps points to a kind of Circle, good
if (auto pc = dynamic_cast<Circle*>(ps)) { ... } // execute if ps points to a kind of Circle, good

if (auto pc = dynamic_cast<Circle>(ps); pc != nullptr) { ... } // not recommended
if (auto pc = dynamic_cast<Circle*>(ps); pc != nullptr) { ... } // not recommended

##### Example

Expand Down

0 comments on commit 8789617

Please sign in to comment.