summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/ADT/StringRef.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/llvm/include/llvm/ADT/StringRef.h b/llvm/include/llvm/ADT/StringRef.h
index d3683c79e50..a053b414a10 100644
--- a/llvm/include/llvm/ADT/StringRef.h
+++ b/llvm/include/llvm/ADT/StringRef.h
@@ -73,14 +73,14 @@ namespace llvm {
/// Construct an empty string ref.
/*implicit*/ StringRef() : Data(nullptr), Length(0) {}
+ /// Disable conversion from nullptr. This prevents things like
+ /// if (S == nullptr)
StringRef(std::nullptr_t) = delete;
/// Construct a string ref from a cstring.
+ LLVM_ATTRIBUTE_ALWAYS_INLINE
/*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
OpenPOWER on IntegriCloud