From 98b4bbb35efc3937b24e1de5559c974bd2578a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Mon, 21 Jul 2025 11:53:00 +0200 Subject: [PATCH] Deprecate comparison operators on MessageInfo --- src/catch2/internal/catch_message_info.hpp | 3 +++ src/catch2/internal/catch_run_context.cpp | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/catch2/internal/catch_message_info.hpp b/src/catch2/internal/catch_message_info.hpp index 1ef43fda..ded098f5 100644 --- a/src/catch2/internal/catch_message_info.hpp +++ b/src/catch2/internal/catch_message_info.hpp @@ -8,6 +8,7 @@ #ifndef CATCH_MESSAGE_INFO_HPP_INCLUDED #define CATCH_MESSAGE_INFO_HPP_INCLUDED +#include #include #include #include @@ -27,9 +28,11 @@ namespace Catch { ResultWas::OfType type; unsigned int sequence; + DEPRECATED( "Explicitly use the 'sequence' member instead" ) bool operator == (MessageInfo const& other) const { return sequence == other.sequence; } + DEPRECATED( "Explicitly use the 'sequence' member instead" ) bool operator < (MessageInfo const& other) const { return sequence < other.sequence; } diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp index ae170d1f..a6b99c02 100644 --- a/src/catch2/internal/catch_run_context.cpp +++ b/src/catch2/internal/catch_run_context.cpp @@ -439,8 +439,14 @@ namespace Catch { m_messages.push_back(message); } - void RunContext::popScopedMessage(MessageInfo const & message) { - m_messages.erase(std::remove(m_messages.begin(), m_messages.end(), message), m_messages.end()); + void RunContext::popScopedMessage( MessageInfo const& message ) { + m_messages.erase( + std::remove_if( m_messages.begin(), + m_messages.end(), + [id = message.sequence]( MessageInfo const& msg ) { + return msg.sequence == id; + } ), + m_messages.end() ); } void RunContext::emplaceUnscopedMessage( MessageBuilder&& builder ) {