mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-23 11:43:29 +01:00
Change how non-nullness is enforce in StringRef constructor
This commit is contained in:
parent
f80f28e09a
commit
0adb04807a
@ -27,6 +27,13 @@ namespace Catch {
|
|||||||
return s_emptyStringRef;
|
return s_emptyStringRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char const* enforceNonNull(char const* ptr) {
|
||||||
|
if (ptr == nullptr) {
|
||||||
|
std::abort();
|
||||||
|
}
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StringRef::StringRef() noexcept
|
StringRef::StringRef() noexcept
|
||||||
@ -47,10 +54,8 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StringRef::StringRef(char const* rawChars) noexcept
|
StringRef::StringRef(char const* rawChars) noexcept
|
||||||
: m_start(rawChars),
|
: m_start( enforceNonNull(rawChars) ),
|
||||||
m_size( (rawChars != nullptr)?
|
m_size( static_cast<size_type>(std::strlen(rawChars)))
|
||||||
(static_cast<size_type>(std::strlen(rawChars))):
|
|
||||||
throw std::domain_error("Cannot create StringRef from nullptr"))
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
StringRef::StringRef( char const* rawChars, size_type size ) noexcept
|
StringRef::StringRef( char const* rawChars, size_type size ) noexcept
|
||||||
|
Loading…
Reference in New Issue
Block a user