Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit bb748a1

Browse files
author
Zachary Turner
committed
Allow StringRef to be constructed from a null pointer.
Differential Revision: https://reviews.llvm.org/D24904 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282433 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 134d28b commit bb748a1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

include/llvm/ADT/StringRef.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ namespace llvm {
7373
/// Construct an empty string ref.
7474
/*implicit*/ StringRef() : Data(nullptr), Length(0) {}
7575

76+
/// Disable conversion from nullptr. This prevents things like
77+
/// if (S == nullptr)
7678
StringRef(std::nullptr_t) = delete;
7779

7880
/// Construct a string ref from a cstring.
81+
LLVM_ATTRIBUTE_ALWAYS_INLINE
7982
/*implicit*/ StringRef(const char *Str)
80-
: Data(Str) {
81-
assert(Str && "StringRef cannot be built from a NULL argument");
82-
Length = ::strlen(Str); // invoking strlen(NULL) is undefined behavior
83-
}
83+
: Data(Str), Length(Str ? ::strlen(Str) : 0) {}
8484

8585
/// Construct a string ref from a pointer and length.
8686
LLVM_ATTRIBUTE_ALWAYS_INLINE

0 commit comments

Comments
 (0)