diff --git a/include/llvm/ADT/StringRef.h b/include/llvm/ADT/StringRef.h index 17a428cfd1d..17c5e403cc0 100644 --- a/include/llvm/ADT/StringRef.h +++ b/include/llvm/ADT/StringRef.h @@ -215,6 +215,15 @@ namespace llvm { return Data[Index]; } + /// Disallow accidental assignment from a temporary std::string. + /// + /// The declaration here is extra complicated so that `stringRef = {}` + /// and `stringRef = "abc"` continue to select the move assignment operator. + template + typename std::enable_if::value, + StringRef>::type & + operator=(T &&Str) = delete; + /// @} /// @name Type Conversions /// @{