AssertionHandler uses RunContext directly to avoid virtual dispatch

This commit is contained in:
Martin Hořeňovský
2026-04-13 22:56:55 +02:00
parent be2dfb45cc
commit 10f62484bf
2 changed files with 7 additions and 3 deletions
@@ -11,6 +11,7 @@
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
#include <catch2/internal/catch_context.hpp>
#include <catch2/internal/catch_debugger.hpp>
#include <catch2/internal/catch_run_context.hpp>
#include <catch2/internal/catch_test_failure_exception.hpp>
#include <catch2/matchers/catch_matchers_string.hpp>
@@ -26,7 +27,7 @@ namespace Catch {
StringRef capturedExpression,
ResultDisposition::Flags resultDisposition )
: m_assertionInfo{ macroName, lineInfo, capturedExpression, resultDisposition },
m_resultCapture( getResultCapture() )
m_resultCapture( static_cast<RunContext&>(getResultCapture()) )
{
m_resultCapture.notifyAssertionStarted( m_assertionInfo );
}
@@ -15,7 +15,7 @@
namespace Catch {
class IResultCapture;
class RunContext;
struct AssertionReaction {
bool shouldDebugBreak = false;
@@ -27,7 +27,10 @@ namespace Catch {
AssertionInfo m_assertionInfo;
AssertionReaction m_reaction;
bool m_completed = false;
IResultCapture& m_resultCapture;
// Since all uses are hidden in the .cpp file, we can directly use
// the final type and avoid going through virtual dispatch, without
// massive compilation time overhead.
RunContext& m_resultCapture;
void finishIncomplete();