diff --git a/include/internal/catch_fatal_condition.cpp b/include/internal/catch_fatal_condition.cpp index 39b63455..ac2863d2 100644 --- a/include/internal/catch_fatal_condition.cpp +++ b/include/internal/catch_fatal_condition.cpp @@ -15,7 +15,7 @@ namespace { // Report the error condition void reportFatal( char const * const message ) { - Catch::getCurrentContext().getResultCapture()->handleFatalErrorCondition( message ); + Catch::getCurrentContext().getResultCapture()->handleFatalErrorCondition( Catch::StringRef::fromRaw( message ) ); } } diff --git a/include/internal/catch_stringref.cpp b/include/internal/catch_stringref.cpp index 49d9629f..41c6ac5c 100644 --- a/include/internal/catch_stringref.cpp +++ b/include/internal/catch_stringref.cpp @@ -16,6 +16,11 @@ #include namespace Catch { + auto StringRef::fromRaw( char const* rawChars ) -> StringRef { + return rawChars + ? StringRef( rawChars,static_cast(std::strlen(rawChars) ) ) + : StringRef(); + } StringRef::operator std::string() const { return std::string( m_start, m_size ); diff --git a/include/internal/catch_stringref.h b/include/internal/catch_stringref.h index 2a9ad4c2..29dcde26 100644 --- a/include/internal/catch_stringref.h +++ b/include/internal/catch_stringref.h @@ -10,8 +10,6 @@ #include #include #include -#include -#include namespace Catch { @@ -56,12 +54,11 @@ namespace Catch { other.m_data = nullptr; } - StringRef( char const* rawChars ) noexcept - : m_start( rawChars ), - m_size( static_cast(std::strlen(rawChars))) - { - assert( rawChars ); - } + template + StringRef( char const(& rawChars)[Size] ) noexcept + : m_start( rawChars ), + m_size( static_cast( Size-1 ) ) + {} StringRef( char const* rawChars, size_type size ) noexcept : m_start( rawChars ), @@ -85,6 +82,8 @@ namespace Catch { return *this; } + static auto fromRaw( char const *rawChars ) -> StringRef; + operator std::string() const; void swap( StringRef& other ) noexcept;