Force StaticStringImpl constructor to use the constexpr versions of StringImplShape...
authormark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 May 2017 17:11:27 +0000 (17:11 +0000)
committermark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 May 2017 17:11:27 +0000 (17:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=171861

Reviewed by Yusuke Suzuki.

This is strictly necessary for correctness of the StaticStringImpl implementation.
We force the constructor selection by adding an extra dummy argument to the
constexpr versions of the StringImplShape constructors to disambiguate them from
the non-constexpr versions.

* wtf/text/StringImpl.h:
(WTF::StringImplShape::StringImplShape):
(WTF::StringImpl::StaticStringImpl::StaticStringImpl):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@216512 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/text/StringImpl.h

index 1d0c14c..43d43ce 100644 (file)
@@ -1,3 +1,19 @@
+2017-05-09  Mark Lam  <mark.lam@apple.com>
+
+        Force StaticStringImpl constructor to use the constexpr versions of StringImplShape constructors.
+        https://bugs.webkit.org/show_bug.cgi?id=171861
+
+        Reviewed by Yusuke Suzuki.
+
+        This is strictly necessary for correctness of the StaticStringImpl implementation.
+        We force the constructor selection by adding an extra dummy argument to the
+        constexpr versions of the StringImplShape constructors to disambiguate them from
+        the non-constexpr versions.
+
+        * wtf/text/StringImpl.h:
+        (WTF::StringImplShape::StringImplShape):
+        (WTF::StringImpl::StaticStringImpl::StaticStringImpl):
+
 2017-05-09  Zan Dobersek  <zdobersek@igalia.com>
 
         Upstream the WPE port
index de9a771..48de72b 100644 (file)
@@ -146,8 +146,10 @@ protected:
         , m_hashAndFlags(hashAndFlags)
     { }
 
+    enum ConstructWithConstExprTag { ConstructWithConstExpr };
+    
     template<unsigned charactersCount>
-    constexpr StringImplShape(unsigned refCount, unsigned length, const char (&characters)[charactersCount], unsigned hashAndFlags)
+    constexpr StringImplShape(unsigned refCount, unsigned length, const char (&characters)[charactersCount], unsigned hashAndFlags, ConstructWithConstExprTag)
         : m_refCount(refCount)
         , m_length(length)
         , m_data8(reinterpret_cast<const LChar*>(characters))
@@ -155,7 +157,7 @@ protected:
     { }
     
     template<unsigned charactersCount>
-    constexpr StringImplShape(unsigned refCount, unsigned length, const char16_t (&characters)[charactersCount], unsigned hashAndFlags)
+    constexpr StringImplShape(unsigned refCount, unsigned length, const char16_t (&characters)[charactersCount], unsigned hashAndFlags, ConstructWithConstExprTag)
         : m_refCount(refCount)
         , m_length(length)
         , m_data16(reinterpret_cast<const UChar*>(characters))
@@ -593,14 +595,14 @@ public:
         template<unsigned charactersCount>
         constexpr StaticStringImpl(const char (&characters)[charactersCount], StringKind stringKind = StringNormal)
             : StringImplShape(s_refCountFlagIsStaticString, charactersCount - 1, characters,
-                s_hashFlag8BitBuffer | s_hashFlagDidReportCost | stringKind | BufferInternal | (StringHasher::computeLiteralHashAndMaskTop8Bits(characters) << s_flagCount))
+                s_hashFlag8BitBuffer | s_hashFlagDidReportCost | stringKind | BufferInternal | (StringHasher::computeLiteralHashAndMaskTop8Bits(characters) << s_flagCount), ConstructWithConstExpr)
         {
         }
 
         template<unsigned charactersCount>
         constexpr StaticStringImpl(const char16_t (&characters)[charactersCount], StringKind stringKind = StringNormal)
             : StringImplShape(s_refCountFlagIsStaticString, charactersCount - 1, characters,
-                s_hashFlagDidReportCost | stringKind | BufferInternal | (StringHasher::computeLiteralHashAndMaskTop8Bits(characters) << s_flagCount))
+                s_hashFlagDidReportCost | stringKind | BufferInternal | (StringHasher::computeLiteralHashAndMaskTop8Bits(characters) << s_flagCount), ConstructWithConstExpr)
         {
         }