mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-22 19:33: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;
|
||||
}
|
||||
|
||||
char const* enforceNonNull(char const* ptr) {
|
||||
if (ptr == nullptr) {
|
||||
std::abort();
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
StringRef::StringRef() noexcept
|
||||
@ -47,10 +54,8 @@ namespace Catch {
|
||||
}
|
||||
|
||||
StringRef::StringRef(char const* rawChars) noexcept
|
||||
: m_start(rawChars),
|
||||
m_size( (rawChars != nullptr)?
|
||||
(static_cast<size_type>(std::strlen(rawChars))):
|
||||
throw std::domain_error("Cannot create StringRef from nullptr"))
|
||||
: m_start( enforceNonNull(rawChars) ),
|
||||
m_size( static_cast<size_type>(std::strlen(rawChars)))
|
||||
{}
|
||||
|
||||
StringRef::StringRef( char const* rawChars, size_type size ) noexcept
|
||||
|
Loading…
Reference in New Issue
Block a user