[PATCH] D24904: Allow StringRef to be constructed with a null pointer
Zachary Turner via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 25 22:00:14 PDT 2016
zturner created this revision.
zturner added reviewers: lattner, mehdi_amini, pete.
zturner added a subscriber: llvm-commits.
Making it official with a CL.
See http://lists.llvm.org/pipermail/llvm-dev/2016-September/105163.html for context and discussion.
Will wait a little while to commit this regardless of LGTM just in case someone has an objection.
https://reviews.llvm.org/D24904
Files:
include/llvm/ADT/StringRef.h
Index: include/llvm/ADT/StringRef.h
===================================================================
--- include/llvm/ADT/StringRef.h
+++ include/llvm/ADT/StringRef.h
@@ -73,14 +73,9 @@
/// Construct an empty string ref.
/*implicit*/ StringRef() : Data(nullptr), Length(0) {}
- StringRef(std::nullptr_t) = delete;
-
/// Construct a string ref from a cstring.
/*implicit*/ StringRef(const char *Str)
- : Data(Str) {
- assert(Str && "StringRef cannot be built from a NULL argument");
- Length = ::strlen(Str); // invoking strlen(NULL) is undefined behavior
- }
+ : Data(Str), Length(Str ? ::strlen(Str) : 0) {}
/// Construct a string ref from a pointer and length.
LLVM_ATTRIBUTE_ALWAYS_INLINE
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24904.72438.patch
Type: text/x-patch
Size: 763 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160926/8da5d709/attachment.bin>
More information about the llvm-commits
mailing list