[PATCH] D26568: [ADT] Delete Twine constructors which accept StringRef rvalues (NFC)

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 11 15:44:03 PST 2016


vsk updated this revision to Diff 77687.
vsk added a comment.

- Upload a diff with context.


https://reviews.llvm.org/D26568

Files:
  include/llvm/ADT/Twine.h


Index: include/llvm/ADT/Twine.h
===================================================================
--- include/llvm/ADT/Twine.h
+++ include/llvm/ADT/Twine.h
@@ -370,6 +370,13 @@
       assert(isValid() && "Invalid twine!");
     }
 
+    /// Do not construct from StringRef rvalues. Twine stores a *pointer to a
+    /// StringRef*, not a StringRef. Taking the address of a StringRef rvalue
+    /// could easily give us a dangling pointer.
+    /*implicit*/ Twine(StringRef &&) = delete;
+    /*implicit*/ Twine(const char *, StringRef &&) = delete;
+    /*implicit*/ Twine(StringRef &&, const char *) = delete;
+
     /// Create a 'null' string, which is an empty string that always
     /// concatenates to form another empty string.
     static Twine createNull() {
@@ -522,13 +529,17 @@
     return Twine(LHS, RHS);
   }
 
+  inline Twine operator+(const char *, StringRef &&) = delete;
+
   /// Additional overload to guarantee simplified codegen; this is equivalent to
   /// concat().
 
   inline Twine operator+(const StringRef &LHS, const char *RHS) {
     return Twine(LHS, RHS);
   }
 
+  inline Twine operator+(StringRef &&, const char *) = delete;
+
   inline raw_ostream &operator<<(raw_ostream &OS, const Twine &RHS) {
     RHS.print(OS);
     return OS;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26568.77687.patch
Type: text/x-patch
Size: 1272 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161111/4ff624cc/attachment.bin>


More information about the llvm-commits mailing list