[libcxx-commits] [PATCH] D102360: [libcxx] [test] Change the generic_string_alloc test to do a conversion that also does something on windows

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed May 12 13:07:52 PDT 2021

mstorsjo created this revision.
mstorsjo requested review of this revision.
Herald added a project: libc++.
Herald added a reviewer: libc++.

On windows, the native path char type is wchar_t - therefore, this test
didn't actually do the conversion that the test was supposed to exercise.
Instead use a type that ends up converted on all current platforms
(char32_t), and use the typedef CharT instead of hardcoding wchar_t in
multiple places.

The charset conversions on windows do cause extra allocations outside of
the provided allocator though, so that bit of the test has to be waived
now that the test actually does something. (Other tests have similar
TEST_NOT_WIN32() for allocation checks for charset conversions.)

  rG LLVM Github Monorepo



Index: libcxx/test/std/input.output/filesystems/class.path/path.member/path.generic.obs/generic_string_alloc.pass.cpp
--- libcxx/test/std/input.output/filesystems/class.path/path.member/path.generic.obs/generic_string_alloc.pass.cpp
+++ libcxx/test/std/input.output/filesystems/class.path/path.member/path.generic.obs/generic_string_alloc.pass.cpp
@@ -39,17 +39,19 @@
 int main(int, char**)
   using namespace fs;
-  using CharT = wchar_t;
+  using CharT = char32_t;
   using Traits = std::char_traits<CharT>;
   using Alloc = malloc_allocator<CharT>;
   using Str = std::basic_string<CharT, Traits, Alloc>;
-  const wchar_t* expect = longString;
+  const CharT* expect = longString;
   const path p((const char*)longString);
-    DisableAllocationGuard g;
+    // On Windows, charset conversions cause allocations outside of the
+    // provided allocator.
+    TEST_NOT_WIN32(DisableAllocationGuard g);
     Alloc a;
     Alloc::disable_default_constructor = true;
-    Str s = p.generic_string<wchar_t, Traits, Alloc>(a);
+    Str s = p.generic_string<CharT, Traits, Alloc>(a);
     assert(s == expect);
     assert(Alloc::alloc_count > 0);
     assert(Alloc::outstanding_alloc() == 1);

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102360.344926.patch
Type: text/x-patch
Size: 1266 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210512/4057d0d9/attachment.bin>

More information about the libcxx-commits mailing list