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,6 +529,8 @@ return Twine(LHS, RHS); } + inline Twine operator+(const char *, StringRef &&) = delete; + /// Additional overload to guarantee simplified codegen; this is equivalent to /// concat(). @@ -529,6 +538,8 @@ 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;