diff options
author | Marco Bubke <marco.bubke@qt.io> | 2017-10-24 19:38:19 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2017-11-13 15:45:48 +0000 |
commit | 95c55e5c5e3262d37b6953e9612ea17a77ba63b2 (patch) | |
tree | 6d590be377e03e6b8d520485c1f5213ee8381293 /src/libs/utils/smallstringlayout.h | |
parent | 9678c86e40d5d97abcb99cd370186cb2cc35a820 (diff) |
Utils: Fix small string layout for Clang 5.0
We were initializing reference but then accessing shortString.
Change-Id: If2d824f96b505b8f0131373916759cd868b07bdb
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'src/libs/utils/smallstringlayout.h')
-rw-r--r-- | src/libs/utils/smallstringlayout.h | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/libs/utils/smallstringlayout.h b/src/libs/utils/smallstringlayout.h index f831ac0aa9a..fc39922b63c 100644 --- a/src/libs/utils/smallstringlayout.h +++ b/src/libs/utils/smallstringlayout.h @@ -106,36 +106,38 @@ struct ALIGNAS_16 StringDataLayout { { } - template<size_type Size> + template<size_type Size, + typename std::enable_if_t<Size <= MaximumShortStringDataAreaSize, int> = 0> constexpr StringDataLayout(const char(&string)[Size]) noexcept #if __cpp_constexpr < 201304 : reference({{string, Size - 1, 0}, {}, 0, true, true}) +#else + : shortString(ShortStringLayout<MaximumShortStringDataAreaSize>{}) #endif { #if __cpp_constexpr >= 201304 - if (Size <= MaximumShortStringDataAreaSize) { - for (size_type i = 0; i < Size; ++i) - shortString.string[i] = string[i]; + for (size_type i = 0; i < Size; ++i) + shortString.string[i] = string[i]; #if defined(__GNUC__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Woverflow" - shortString.shortStringSize = std::uint8_t(Size) - 1; + shortString.shortStringSize = std::uint8_t(Size) - 1; #pragma GCC diagnostic pop #endif - shortString.isReference = false; - shortString.isReadOnlyReference = false; - } else { - reference.data.pointer = string; - reference.data.size = Size - 1; - reference.data.capacity = 0; - reference.shortStringSize = 0; - reference.isReference = true; - reference.isReadOnlyReference = true; - } + shortString.isReference = false; + shortString.isReadOnlyReference = false; + #endif } + template<size_type Size, + typename std::enable_if_t<!(Size <= MaximumShortStringDataAreaSize), int> = 1> + constexpr StringDataLayout(const char(&string)[Size]) noexcept + : reference({{string, Size - 1, 0}, {}, 0, true, true}) + { + } + constexpr static size_type shortStringCapacity() noexcept { @@ -145,7 +147,7 @@ struct ALIGNAS_16 StringDataLayout { union { AllocatedLayout<MaximumShortStringDataAreaSize> allocated; ReferenceLayout<MaximumShortStringDataAreaSize> reference; - ShortStringLayout<MaximumShortStringDataAreaSize> shortString = ShortStringLayout<MaximumShortStringDataAreaSize>(); + ShortStringLayout<MaximumShortStringDataAreaSize> shortString; }; }; |