[libcxx-commits] [libcxx] 6b90f67 - [libc++][test] Make some string tests MSVC-friendly

Casey Carter via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jan 9 15:00:17 PST 2023


Author: Casey Carter
Date: 2023-01-09T15:00:07-08:00
New Revision: 6b90f6745ac78933baf2d56b1f32c274a52c2ec0

URL: https://github.com/llvm/llvm-project/commit/6b90f6745ac78933baf2d56b1f32c274a52c2ec0
DIFF: https://github.com/llvm/llvm-project/commit/6b90f6745ac78933baf2d56b1f32c274a52c2ec0.diff

LOG: [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 `<string>` 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

Added: 
    

Modified: 
    libcxx/test/std/strings/basic.string/string.cons/dtor.pass.cpp
    libcxx/test/std/strings/basic.string/string.ops/string_substr/substr_rvalue.pass.cpp

Removed: 
    


################################################################################
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 0464bc3890a6b..07e9a60397d42 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<std::string>::value, "");
@@ -45,7 +45,8 @@ TEST_CONSTEXPR_CXX20 bool test() {
   {
     std::basic_string<char, std::char_traits<char>, test_allocator<char>> str2((test_allocator<char>(&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 13019ae351077..c3c6c3f56b919 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 <algorithm>
+#include <stdexcept>
 #include <string>
 
 #include "constexpr_char_traits.h"
@@ -26,7 +27,7 @@ constexpr struct should_throw_exception_t {
 } should_throw_exception;
 
 template <class S>
-constexpr void test(S orig, size_t pos, ptr
diff _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, ptr
diff _t n, S expected) {
 }
 
 template <class S>
-constexpr void test(S orig, size_t pos, ptr
diff _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 {


        


More information about the libcxx-commits mailing list