From 98f1e46602118129fb289bb010b433a30fc95b7a Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 10 Oct 2016 17:31:26 +0100 Subject: [PATCH] C.146 Compare pb2->id() instead of pb2 Fixes #504 --- CppCoreGuidelines.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 204f48a..1f561d6 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -6765,14 +6765,14 @@ Consider: cout << pb2->id(); // "D" if (pb1->id() == pb2->id()) // *pb1 is the same type as *pb2 - if (pb2 == "D") { // looks innocent - D* pd = static_cast(pb1); - // ... + if (pb2->id() == "D") { // looks innocent + D* pd = static_cast(pb1); + // ... } // ... } -The result of `pb2 == "D"` is actually implementation defined. +The result of `pb2->id() == "D"` is actually implementation defined. We added it to warn of the dangers of home-brew RTTI. This code may work as expected for years, just to fail on a new machine, new compiler, or a new linker that does not unify character literals.