From 3b19458fed6cf6f34970a6103c70abbca9d63f92 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Thu, 28 Apr 2016 07:54:57 +0100 Subject: [PATCH] Removed use of dynamic_cast for MultipleReporters (Thanks to #630, #636 and #648) --- include/internal/catch_interfaces_reporter.h | 3 +++ include/reporters/catch_reporter_multi.hpp | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/internal/catch_interfaces_reporter.h b/include/internal/catch_interfaces_reporter.h index d1c6e70..98e2cd6 100644 --- a/include/internal/catch_interfaces_reporter.h +++ b/include/internal/catch_interfaces_reporter.h @@ -219,6 +219,7 @@ namespace Catch bool aborting; }; + class MultipleReporters; struct IStreamingReporter : IShared { virtual ~IStreamingReporter(); @@ -247,6 +248,8 @@ namespace Catch virtual void testRunEnded( TestRunStats const& testRunStats ) = 0; virtual void skipTest( TestCaseInfo const& testInfo ) = 0; + + virtual MultipleReporters* tryAsMulti() { return CATCH_NULL; } }; diff --git a/include/reporters/catch_reporter_multi.hpp b/include/reporters/catch_reporter_multi.hpp index d328266..7fc08f6 100644 --- a/include/reporters/catch_reporter_multi.hpp +++ b/include/reporters/catch_reporter_multi.hpp @@ -118,13 +118,18 @@ public: // IStreamingReporter ++it ) (*it)->skipTest( testInfo ); } + + virtual MultipleReporters* tryAsMulti() CATCH_OVERRIDE { + return this; + } + }; Ptr addReporter( Ptr const& existingReporter, Ptr const& additionalReporter ) { Ptr resultingReporter; if( existingReporter ) { - MultipleReporters* multi = dynamic_cast( existingReporter.get() ); + MultipleReporters* multi = existingReporter->tryAsMulti(); if( !multi ) { multi = new MultipleReporters; resultingReporter = Ptr( multi );