[Lldb-commits] [PATCH] D27780: Make OptionDefinition structure store a StringRef

Zachary Turner via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 7 06:36:51 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rG182b4652e542: [StringRef] Add enable-if to StringLiteral. (authored by zturner).
Herald added subscribers: llvm-commits, dexonsmith.
Herald added a project: LLVM.

Changed prior to commit:
  https://reviews.llvm.org/D27780?vs=81625&id=223552#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D27780/new/

https://reviews.llvm.org/D27780

Files:
  llvm/include/llvm/ADT/StringRef.h


Index: llvm/include/llvm/ADT/StringRef.h
===================================================================
--- llvm/include/llvm/ADT/StringRef.h
+++ llvm/include/llvm/ADT/StringRef.h
@@ -838,22 +838,21 @@
 
   /// A wrapper around a string literal that serves as a proxy for constructing
   /// global tables of StringRefs with the length computed at compile time.
-  /// Using this class with a non-literal char array is considered undefined
-  /// behavior.  To prevent this, it is recommended that StringLiteral *only*
-  /// be used in a constexpr context, as such:
+  /// In order to avoid the invocation of a global constructor, StringLiteral
+  /// should *only* be used in a constexpr context, as such:
   ///
   /// constexpr StringLiteral S("test");
   ///
-  /// Note: There is a subtle behavioral difference in the constructor of
-  /// StringRef and StringLiteral, as illustrated below:
-  ///
-  /// constexpr StringLiteral S("a\0b");  // S.size() == 3
-  /// StringRef S("a\0b");  // S.size() == 1
-  ///
   class StringLiteral : public StringRef {
   public:
     template <size_t N>
-    constexpr StringLiteral(const char (&Str)[N]) : StringRef(Str, N - 1) {}
+    constexpr StringLiteral(const char (&Str)[N])
+#if __has_attribute(enable_if)
+        __attribute((enable_if(__builtin_strlen(Str) == N - 1,
+                               "invalid string literal")))
+#endif
+        : StringRef(Str, N - 1) {
+    }
   };
 
   /// @name StringRef Comparison Operators
@@ -865,9 +864,7 @@
   }
 
   LLVM_ATTRIBUTE_ALWAYS_INLINE
-  inline bool operator!=(StringRef LHS, StringRef RHS) {
-    return !(LHS == RHS);
-  }
+  inline bool operator!=(StringRef LHS, StringRef RHS) { return !(LHS == RHS); }
 
   inline bool operator<(StringRef LHS, StringRef RHS) {
     return LHS.compare(RHS) == -1;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27780.223552.patch
Type: text/x-patch
Size: 1815 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20191007/ac2d839e/attachment.bin>


More information about the lldb-commits mailing list