Skip to content
Snippets Groups Projects
Commit d543def2 authored by Zachary Turner's avatar Zachary Turner
Browse files

Allow StringRef to be constructed from a null pointer.

Differential Revision: https://reviews.llvm.org/D24904

llvm-svn: 282433
parent f7e07256
No related branches found
No related tags found
No related merge requests found
...@@ -73,14 +73,14 @@ namespace llvm { ...@@ -73,14 +73,14 @@ namespace llvm {
/// Construct an empty string ref. /// Construct an empty string ref.
/*implicit*/ StringRef() : Data(nullptr), Length(0) {} /*implicit*/ StringRef() : Data(nullptr), Length(0) {}
/// Disable conversion from nullptr. This prevents things like
/// if (S == nullptr)
StringRef(std::nullptr_t) = delete; StringRef(std::nullptr_t) = delete;
/// Construct a string ref from a cstring. /// Construct a string ref from a cstring.
LLVM_ATTRIBUTE_ALWAYS_INLINE
/*implicit*/ StringRef(const char *Str) /*implicit*/ StringRef(const char *Str)
: Data(Str) { : Data(Str), Length(Str ? ::strlen(Str) : 0) {}
assert(Str && "StringRef cannot be built from a NULL argument");
Length = ::strlen(Str); // invoking strlen(NULL) is undefined behavior
}
/// Construct a string ref from a pointer and length. /// Construct a string ref from a pointer and length.
LLVM_ATTRIBUTE_ALWAYS_INLINE LLVM_ATTRIBUTE_ALWAYS_INLINE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment