[libc++][test] Make deallocate_size.pass.cpp MSVC-friendly#165162
Merged
frederick-vs-ja merged 6 commits intollvm:mainfrom Oct 31, 2025
Merged
[libc++][test] Make deallocate_size.pass.cpp MSVC-friendly#165162frederick-vs-ja merged 6 commits intollvm:mainfrom
deallocate_size.pass.cpp MSVC-friendly#165162frederick-vs-ja merged 6 commits intollvm:mainfrom
Conversation
Member
|
@llvm/pr-subscribers-libcxx Author: A. Jiang (frederick-vs-ja) ChangesThis patch contains several changes to
Full diff: https://github.com/llvm/llvm-project/pull/165162.diff 1 Files Affected:
diff --git a/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp b/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp
index 00f9e2b846783..b402bbc9bf823 100644
--- a/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp
@@ -12,12 +12,13 @@
#include <string>
#include <cassert>
+#include <cstddef>
#include <cstdint>
#include <type_traits>
#include "test_macros.h"
-static int allocated_;
+static std::ptrdiff_t allocated_;
template <class T, class Sz>
struct test_alloc {
@@ -40,13 +41,13 @@ struct test_alloc {
TEST_CONSTEXPR test_alloc(const test_alloc<U, Sz>&) TEST_NOEXCEPT {}
pointer allocate(size_type n, const void* = nullptr) {
- allocated_ += n;
- return std::allocator<value_type>().allocate(n);
+ allocated_ += static_cast<std::ptrdiff_t>(n);
+ return std::allocator<value_type>().allocate(static_cast<std::size_t>(n));
}
void deallocate(pointer p, size_type s) {
- allocated_ -= s;
- std::allocator<value_type>().deallocate(p, s);
+ allocated_ -= static_cast<std::ptrdiff_t>(s);
+ std::allocator<value_type>().deallocate(p, static_cast<std::size_t>(s));
}
template <class U>
@@ -68,7 +69,11 @@ void test() {
using Str = std::basic_string<char, std::char_traits<char>, test_alloc<char, Sz> >;
{
Str s(i, 't');
+#ifdef _MSVC_STL_VERSION // MSVC STL dynamically allocates one container proxy object in debug modes.
+ assert(allocated_ == 0 || allocated_ == 1 || allocated_ >= i);
+#else // ^^^ MSVC STL / other vvv
assert(allocated_ == 0 || allocated_ >= i);
+#endif // ^^^ other ^^^
}
}
assert(allocated_ == 0);
|
philnik777
reviewed
Oct 27, 2025
libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp
Outdated
Show resolved
Hide resolved
libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp
Outdated
Show resolved
Hide resolved
d597c41 to
8fc6630
Compare
This patch contains several changes to `deallocate_size.pass.cpp`: 1. `static_cast`-ing parameters to suitable types to avoid narrowing. 2. Changeing the type of `allocated_` to possibly larger and seemingly more appropriate `ptrdiff_t`. 3. Avoiding `assert`-ing count of allocations when a `basic_string` is allocated, just `assert`-ing after destruction instead.
8fc6630 to
44e2430
Compare
deallocate_size.pass.cpp MSVC-STL-friendlydeallocate_size.pass.cpp MSVC-friendly
philnik777
reviewed
Oct 28, 2025
libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp
Show resolved
Hide resolved
libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp
Outdated
Show resolved
Hide resolved
libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp
Outdated
Show resolved
Hide resolved
philnik777
reviewed
Oct 29, 2025
libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp
Outdated
Show resolved
Hide resolved
libcxx/test/std/strings/basic.string/string.capacity/deallocate_size.pass.cpp
Outdated
Show resolved
Hide resolved
philnik777
approved these changes
Oct 30, 2025
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/94/builds/12230 Here is the relevant piece of the build log for the reference |
DEBADRIBASAK
pushed a commit
to DEBADRIBASAK/llvm-project
that referenced
this pull request
Nov 3, 2025
…5162) This patch contains several changes to `deallocate_size.pass.cpp`: 1. `static_cast`-ing some parameters to `size_t` to avoid narrowing. 2. Changing the type of loop variable `i` to `unsigned int` avoid signedness mismatch with the constructor parameter. 3. Separately counting allocations and deallocations in variables `allocated_` and `deallocated_`, and changing their type to `uint64_t`. 4. Avoiding `assert`-ing count of allocations when a `basic_string` is allocated, just `assert`-ing after destruction instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patch contains several changes to
deallocate_size.pass.cpp:static_cast-ing some parameters tosize_tto avoid narrowing.itounsigned intavoid signedness mismatch with the constructor parameter.allocated_anddeallocated_, and changing their type touint64_t.assert-ing count of allocations when abasic_stringis allocated, justassert-ing after destruction instead.