[llvm] c9a0e74 - Revert "PR51018: Disallow explicit construction of StringRef from SmallString due to ambiguity in C++23"

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 8 13:47:23 PDT 2021


Author: David Blaikie
Date: 2021-07-08T13:46:36-07:00
New Revision: c9a0e74697778a7f2d5da2a22fe56a3eec2ec9a8

URL: https://github.com/llvm/llvm-project/commit/c9a0e74697778a7f2d5da2a22fe56a3eec2ec9a8
DIFF: https://github.com/llvm/llvm-project/commit/c9a0e74697778a7f2d5da2a22fe56a3eec2ec9a8.diff

LOG: Revert "PR51018: Disallow explicit construction of StringRef from SmallString due to ambiguity in C++23"

This reverts commit e2d30846327c7ec5cc9d2a46aa9bcd9c2c4eff93.

MSVC doesn't seem to resolve the intended ambiguity in implicit
conversion contexts correctly: https://godbolt.org/z/ee16aqv4v

Added: 
    

Modified: 
    llvm/include/llvm/ADT/SmallString.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/SmallString.h b/llvm/include/llvm/ADT/SmallString.h
index 4f83a60aefe6f..56b0639b98cc3 100644
--- a/llvm/include/llvm/ADT/SmallString.h
+++ b/llvm/include/llvm/ADT/SmallString.h
@@ -19,22 +19,10 @@
 
 namespace llvm {
 
-namespace impl {
-template <typename T> struct SmallStringConversionHelper1 {
-  operator StringRef() const { return static_cast<const T *>(this)->str(); }
-};
-struct SmallStringConversionHelper2 {
-  explicit operator StringRef() const = delete;
-};
-} // namespace impl
-
 /// SmallString - A SmallString is just a SmallVector with methods and accessors
 /// that make it work better as a string (e.g. operator+ etc).
-template <unsigned InternalLen>
-class SmallString
-    : public SmallVector<char, InternalLen>,
-      public impl::SmallStringConversionHelper1<SmallString<InternalLen>>,
-      public impl::SmallStringConversionHelper2 {
+template<unsigned InternalLen>
+class SmallString : public SmallVector<char, InternalLen> {
 public:
   /// Default ctor - Initialize to empty.
   SmallString() = default;
@@ -278,6 +266,7 @@ class SmallString
   }
 
   /// Implicit conversion to StringRef.
+  operator StringRef() const { return str(); }
 
   explicit operator std::string() const {
     return std::string(this->data(), this->size());


        


More information about the llvm-commits mailing list