From b8a217fbccef28c62b72d9448785f6c5209c7729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Tue, 23 Sep 2025 15:23:58 +0200 Subject: [PATCH] WIP: allow inlining context retrieval --- .../interfaces/catch_interfaces_capture.hpp | 15 ++++++++++++++- src/catch2/internal/catch_run_context.cpp | 14 +++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/catch2/interfaces/catch_interfaces_capture.hpp b/src/catch2/interfaces/catch_interfaces_capture.hpp index 702ccb4d..adbb6d1e 100644 --- a/src/catch2/interfaces/catch_interfaces_capture.hpp +++ b/src/catch2/interfaces/catch_interfaces_capture.hpp @@ -10,6 +10,7 @@ #include +#include #include #include #include @@ -100,7 +101,19 @@ namespace Catch { virtual void exceptionEarlyReported() = 0; }; - IResultCapture& getResultCapture(); + namespace Detail { + [[noreturn]] + void missingCaptureInstance(); + } + inline IResultCapture& getResultCapture() { + if (auto* capture = getCurrentContext().getResultCapture()) { + return *capture; + } else { + Detail::missingCaptureInstance(); + } + + + } } diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp index fc521f8b..91ea857e 100644 --- a/src/catch2/internal/catch_run_context.cpp +++ b/src/catch2/internal/catch_run_context.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -809,13 +810,6 @@ namespace Catch { } } - IResultCapture& getResultCapture() { - if (auto* capture = getCurrentContext().getResultCapture()) - return *capture; - else - CATCH_INTERNAL_ERROR("No result capture instance"); - } - void IResultCapture::pushScopedMessage( MessageInfo&& message ) { Detail::g_messages.push_back( CATCH_MOVE( message ) ); } @@ -846,4 +840,10 @@ namespace Catch { return getCurrentContext().getConfig()->rngSeed(); } + + namespace Detail { + void missingCaptureInstance() { + CATCH_INTERNAL_ERROR( "No result capture instance" ); + } + } // namespace Detail }