Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include/internal/catch_stringref.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2017-11-13 12:57:55 +0100
committerMartin Hořeňovský2017-11-13 13:04:45 +0100
commit0adb04807a2591fcfc3aa5e7158d2fb136a6568c (patch)
tree106142c0cf744f22f8a5842ca8213e86133c590f /include/internal/catch_stringref.cpp
parentf80f28e09aa5ea1d0a981c300d21bfe35c037f55 (diff)
downloadcatch3-0adb04807a2591fcfc3aa5e7158d2fb136a6568c.tar.gz
Change how non-nullness is enforce in StringRef constructor
Diffstat (limited to 'include/internal/catch_stringref.cpp')
-rw-r--r--include/internal/catch_stringref.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/include/internal/catch_stringref.cpp b/include/internal/catch_stringref.cpp
index 60a522ec..f82e60c3 100644
--- a/include/internal/catch_stringref.cpp
+++ b/include/internal/catch_stringref.cpp
@@ -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