[libcxx-commits] [PATCH] D127672: [libc++] Test the size of basic_string

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jun 13 10:32:49 PDT 2022


philnik created this revision.
philnik added a reviewer: ldionne.
Herald added a project: All.
philnik requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127672

Files:
  libcxx/test/libcxx/strings/basic.string/string_abi.compile.pass.cpp


Index: libcxx/test/libcxx/strings/basic.string/string_abi.compile.pass.cpp
===================================================================
--- /dev/null
+++ libcxx/test/libcxx/strings/basic.string/string_abi.compile.pass.cpp
@@ -0,0 +1,69 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// Ensure that we never change the size of `basic_string`
+
+#include <string>
+
+#include "test_macros.h"
+#include "min_allocator.h"
+#include "test_allocator.h"
+
+template <class CharT>
+using min_string = std::basic_string<CharT, std::char_traits<CharT>, min_allocator<CharT>>;
+
+template <class CharT>
+using test_string = std::basic_string<CharT, std::char_traits<CharT>, test_allocator<CharT>>;
+
+#if __SIZE_WIDTH__ == 64
+
+static_assert(sizeof(std::string) == 24);
+static_assert(sizeof(std::wstring) == 24);
+static_assert(sizeof(min_string<char>) == 24);
+static_assert(sizeof(test_string<char>) == 32);
+
+#ifndef TEST_HAS_NO_CHAR8_T
+static_assert(sizeof(std::u8string) == 24);
+static_assert(sizeof(min_string<char8_t>) == 24);
+static_assert(sizeof(test_string<char8_t>) == 32);
+#endif
+
+#ifndef TEST_HAS_NO_UNICODE_CHARS
+static_assert(sizeof(std::u16string) == 24);
+static_assert(sizeof(std::u32string) == 24);
+static_assert(sizeof(min_string<char16_t>) == 24);
+static_assert(sizeof(min_string<char32_t>) == 24);
+static_assert(sizeof(test_string<char16_t>) == 32);
+static_assert(sizeof(test_string<char32_t>) == 32);
+#endif
+
+#elif __SIZE_WIDTH__ == 32
+
+static_assert(sizeof(std::string) == 12);
+static_assert(sizeof(std::wstring) == 12);
+static_assert(sizeof(min_string<char>) == 12);
+static_assert(sizeof(test_string<char>) == 16);
+
+#ifndef TEST_HAS_NO_CHAR8_T
+static_assert(sizeof(std::u8string) == 12);
+static_assert(sizeof(min_string<char8_t>) == 12);
+static_assert(sizeof(test_string<char8_t>) == 16);
+#endif
+
+#ifndef TEST_HAS_NO_UNICODE_CHARS
+static_assert(sizeof(std::u16string) == 12);
+static_assert(sizeof(std::u32string) == 12);
+static_assert(sizeof(min_string<char16_t>) == 12);
+static_assert(sizeof(min_string<char32_t>) == 12);
+static_assert(sizeof(test_string<char16_t>) == 16);
+static_assert(sizeof(test_string<char32_t>) == 16);
+#endif
+
+#else
+#  error "size_t has an unexpected size"
+#endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127672.436468.patch
Type: text/x-patch
Size: 2586 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220613/5d7afa40/attachment.bin>


More information about the libcxx-commits mailing list