Skip to content

Commit 4d60467

Browse files
committed
[libcxx] Fix printf formats in two tests.
rGcc69d211d0d65d7b introduced several uses of `printf` with format directives `%lu` and `%ld` to format values of type `size_t` and `ptrdiff_t` respectively. That doesn't reliably work in all C implementations, because those types aren't necessarily the same thing as 'long int': sometimes they're not even the same size, and when they are the same size, they might be officially defined as int rather than long (for example), which causes clang to emit a diagnostic for the mismatch. C has special-purpose printf modifier letters for these two types, so it's safer to use them. Changed all `%lu` on `size_t` to `%zu`, and all `%ld` on `ptrdiff_t` to `%td`. Reviewed By: ldionne, #libc Differential Revision: https://reviews.llvm.org/D89545
1 parent 0a7f417 commit 4d60467

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

libcxx/test/libcxx/containers/sequences/deque/spare_block_handling.pass.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ struct ContainerAdaptor : public Adaptor {
3131

3232
template <class Deque>
3333
static void print(const Deque& d) {
34-
std::printf("%lu : __front_spare() == %lu"
35-
" : __back_spare() == %lu"
36-
" : __capacity() == %lu"
37-
" : bytes allocated == %lu\n",
38-
d.size(), d.__front_spare(), d.__back_spare(), d.__capacity(),
39-
malloc_allocator_base::outstanding_bytes);
34+
std::printf("%zu : __front_spare() == %zu"
35+
" : __back_spare() == %zu"
36+
" : __capacity() == %zu"
37+
" : bytes allocated == %zu\n",
38+
d.size(), d.__front_spare(), d.__back_spare(), d.__capacity(),
39+
malloc_allocator_base::outstanding_bytes);
4040
}
4141

4242
template <class T>

libcxx/test/std/containers/associative/map/map.cons/copy_assign.pass.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,21 @@ class counting_allocatorF {
7777
bool balanced_allocs() {
7878
std::vector<int> temp1, temp2;
7979

80-
std::printf("Allocations = %lu, deallocations = %lu\n", ca_allocs.size(), ca_deallocs.size());
80+
std::printf("Allocations = %zu, deallocations = %zu\n", ca_allocs.size(),
81+
ca_deallocs.size());
8182
if (ca_allocs.size() != ca_deallocs.size())
8283
return false;
8384

8485
temp1 = ca_allocs;
8586
std::sort(temp1.begin(), temp1.end());
8687
temp2.clear();
8788
std::unique_copy(temp1.begin(), temp1.end(), std::back_inserter<std::vector<int>>(temp2));
88-
std::printf("There were %lu different allocators\n", temp2.size());
89+
std::printf("There were %zu different allocators\n", temp2.size());
8990

9091
for (std::vector<int>::const_iterator it = temp2.begin(); it != temp2.end(); ++it ) {
9192
std::ptrdiff_t const allocs = std::count(ca_allocs.begin(), ca_allocs.end(), *it);
9293
std::ptrdiff_t const deallocs = std::count(ca_deallocs.begin(), ca_deallocs.end(), *it);
93-
std::printf("%d: %ld vs %ld\n", *it, allocs, deallocs);
94+
std::printf("%d: %td vs %td\n", *it, allocs, deallocs);
9495
if (allocs != deallocs)
9596
return false;
9697
}
@@ -99,12 +100,12 @@ bool balanced_allocs() {
99100
std::sort(temp1.begin(), temp1.end());
100101
temp2.clear();
101102
std::unique_copy(temp1.begin(), temp1.end(), std::back_inserter<std::vector<int>>(temp2));
102-
std::printf("There were %lu different (de)allocators\n", temp2.size());
103+
std::printf("There were %zu different (de)allocators\n", temp2.size());
103104

104105
for (std::vector<int>::const_iterator it = ca_deallocs.begin(); it != ca_deallocs.end(); ++it ) {
105106
std::ptrdiff_t const allocs = std::count(ca_allocs.begin(), ca_allocs.end(), *it);
106107
std::ptrdiff_t const deallocs = std::count(ca_deallocs.begin(), ca_deallocs.end(), *it);
107-
std::printf("%d: %ld vs %ld\n", *it, allocs, deallocs);
108+
std::printf("%d: %td vs %td\n", *it, allocs, deallocs);
108109
if (allocs != deallocs)
109110
return false;
110111
}

0 commit comments

Comments
 (0)