From 6b90f6745ac78933baf2d56b1f32c274a52c2ec0 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Sun, 8 Jan 2023 21:58:56 -0800 Subject: [PATCH] [libc++][test] Make some string tests MSVC-friendly * Using one-or-two letter names for globals is asking for shadowing warnings. * MSVCSTL's container proxy allocations strike again * MSVCSTL's `` doesn't define `std::out_of_range` * `basic_string::substr` takes two arguments of type `size_type`. Let's use that type instead of `size_t` and `ptrdiff_t` to avoid narrowing warnings. Differential Revision: https://reviews.llvm.org/D141253 --- libcxx/test/std/strings/basic.string/string.cons/dtor.pass.cpp | 7 ++++--- .../basic.string/string.ops/string_substr/substr_rvalue.pass.cpp | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/libcxx/test/std/strings/basic.string/string.cons/dtor.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/dtor.pass.cpp index 0464bc3..07e9a60 100644 --- a/libcxx/test/std/strings/basic.string/string.cons/dtor.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.cons/dtor.pass.cpp @@ -29,9 +29,9 @@ struct throwing_alloc // Test that it's possible to take the address of basic_string's destructors // by creating globals which will register their destructors with cxa_atexit. -std::string s; +std::string unused_string; #ifndef TEST_HAS_NO_WIDE_CHARACTERS -std::wstring ws; +std::wstring unused_wide_string; #endif static_assert(std::is_nothrow_destructible::value, ""); @@ -45,7 +45,8 @@ TEST_CONSTEXPR_CXX20 bool test() { { std::basic_string, test_allocator> str2((test_allocator(&alloc_stats))); str2 = "long long string so no SSO"; - assert(alloc_stats.alloc_count == 1); + assert(alloc_stats.alloc_count > 0); + LIBCPP_ASSERT(alloc_stats.alloc_count == 1); } assert(alloc_stats.alloc_count == 0); diff --git a/libcxx/test/std/strings/basic.string/string.ops/string_substr/substr_rvalue.pass.cpp b/libcxx/test/std/strings/basic.string/string.ops/string_substr/substr_rvalue.pass.cpp index 13019ae..c3c6c3f 100644 --- a/libcxx/test/std/strings/basic.string/string.ops/string_substr/substr_rvalue.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.ops/string_substr/substr_rvalue.pass.cpp @@ -13,6 +13,7 @@ // constexpr basic_string substr(size_type pos = 0, size_type n = npos) &&; #include +#include #include #include "constexpr_char_traits.h" @@ -26,7 +27,7 @@ constexpr struct should_throw_exception_t { } should_throw_exception; template -constexpr void test(S orig, size_t pos, ptrdiff_t n, S expected) { +constexpr void test(S orig, typename S::size_type pos, typename S::size_type n, const S expected) { S str = std::move(orig).substr(pos, n); LIBCPP_ASSERT(orig.__invariants()); LIBCPP_ASSERT(str.__invariants()); @@ -34,7 +35,7 @@ constexpr void test(S orig, size_t pos, ptrdiff_t n, S expected) { } template -constexpr void test(S orig, size_t pos, ptrdiff_t n, should_throw_exception_t) { +constexpr void test(S orig, typename S::size_type pos, typename S::size_type n, should_throw_exception_t) { #ifndef TEST_HAS_NO_EXCEPTIONS if (!std::is_constant_evaluated()) { try { -- 2.7.4