diff --git a/include/internal/catch_stringref.h b/include/internal/catch_stringref.h index 64f595b3..4e41bd47 100644 --- a/include/internal/catch_stringref.h +++ b/include/internal/catch_stringref.h @@ -71,10 +71,12 @@ namespace Catch { } auto operator = ( StringRef const &other ) noexcept -> StringRef& { - delete[] m_data; - m_data = nullptr; - m_start = other.m_start; - m_size = other.m_size; + if( this != &other ) { + delete[] m_data; + m_data = nullptr; + m_start = other.m_start; + m_size = other.m_size; + } return *this; } diff --git a/projects/SelfTest/IntrospectiveTests/String.tests.cpp b/projects/SelfTest/IntrospectiveTests/String.tests.cpp index cb2c350c..1a3bf6d2 100644 --- a/projects/SelfTest/IntrospectiveTests/String.tests.cpp +++ b/projects/SelfTest/IntrospectiveTests/String.tests.cpp @@ -92,6 +92,11 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) { REQUIRE( isOwned( ss ) ); REQUIRE( ss.currentData() != s.currentData() ); // different pointer value + + SECTION( "Self-assignment after substring" ) { + ss = ss; + REQUIRE(isOwned(ss) == true); + } } SECTION( "non-zero-based substring") {