[libcxx-commits] [libcxx] 4d60467 - [libcxx] Fix printf formats in two tests.

Simon Tatham via libcxx-commits libcxx-commits at lists.llvm.org
Fri Oct 16 05:47:58 PDT 2020


Author: Simon Tatham
Date: 2020-10-16T13:47:45+01:00
New Revision: 4d60467f99a0b00df230c363170a29e36c8ad798

URL: https://github.com/llvm/llvm-project/commit/4d60467f99a0b00df230c363170a29e36c8ad798
DIFF: https://github.com/llvm/llvm-project/commit/4d60467f99a0b00df230c363170a29e36c8ad798.diff

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

Added: 
    

Modified: 
    libcxx/test/libcxx/containers/sequences/deque/spare_block_handling.pass.cpp
    libcxx/test/std/containers/associative/map/map.cons/copy_assign.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/libcxx/containers/sequences/deque/spare_block_handling.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/spare_block_handling.pass.cpp
index 3a583be96e8e..6b4fcfcb1cf8 100644
--- a/libcxx/test/libcxx/containers/sequences/deque/spare_block_handling.pass.cpp
+++ b/libcxx/test/libcxx/containers/sequences/deque/spare_block_handling.pass.cpp
@@ -31,12 +31,12 @@ struct ContainerAdaptor : public Adaptor {
 
 template <class Deque>
 static void print(const Deque& d) {
-  std::printf("%lu : __front_spare() == %lu"
-                 " : __back_spare() == %lu"
-                 " : __capacity() == %lu"
-                 " : bytes allocated == %lu\n",
-      d.size(), d.__front_spare(), d.__back_spare(), d.__capacity(),
-      malloc_allocator_base::outstanding_bytes);
+  std::printf("%zu : __front_spare() == %zu"
+              " : __back_spare() == %zu"
+              " : __capacity() == %zu"
+              " : bytes allocated == %zu\n",
+              d.size(), d.__front_spare(), d.__back_spare(), d.__capacity(),
+              malloc_allocator_base::outstanding_bytes);
 }
 
 template <class T>

diff  --git a/libcxx/test/std/containers/associative/map/map.cons/copy_assign.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/copy_assign.pass.cpp
index 813669c66c4c..a77bf10b9913 100644
--- a/libcxx/test/std/containers/associative/map/map.cons/copy_assign.pass.cpp
+++ b/libcxx/test/std/containers/associative/map/map.cons/copy_assign.pass.cpp
@@ -77,7 +77,8 @@ class counting_allocatorF {
 bool balanced_allocs() {
     std::vector<int> temp1, temp2;
 
-    std::printf("Allocations = %lu, deallocations = %lu\n", ca_allocs.size(), ca_deallocs.size());
+    std::printf("Allocations = %zu, deallocations = %zu\n", ca_allocs.size(),
+                ca_deallocs.size());
     if (ca_allocs.size() != ca_deallocs.size())
         return false;
 
@@ -85,12 +86,12 @@ bool balanced_allocs() {
     std::sort(temp1.begin(), temp1.end());
     temp2.clear();
     std::unique_copy(temp1.begin(), temp1.end(), std::back_inserter<std::vector<int>>(temp2));
-    std::printf("There were %lu 
diff erent allocators\n", temp2.size());
+    std::printf("There were %zu 
diff erent allocators\n", temp2.size());
 
     for (std::vector<int>::const_iterator it = temp2.begin(); it != temp2.end(); ++it ) {
         std::ptr
diff _t const allocs = std::count(ca_allocs.begin(), ca_allocs.end(), *it);
         std::ptr
diff _t const deallocs = std::count(ca_deallocs.begin(), ca_deallocs.end(), *it);
-        std::printf("%d: %ld vs %ld\n", *it, allocs, deallocs);
+        std::printf("%d: %td vs %td\n", *it, allocs, deallocs);
         if (allocs != deallocs)
             return false;
     }
@@ -99,12 +100,12 @@ bool balanced_allocs() {
     std::sort(temp1.begin(), temp1.end());
     temp2.clear();
     std::unique_copy(temp1.begin(), temp1.end(), std::back_inserter<std::vector<int>>(temp2));
-    std::printf("There were %lu 
diff erent (de)allocators\n", temp2.size());
+    std::printf("There were %zu 
diff erent (de)allocators\n", temp2.size());
 
     for (std::vector<int>::const_iterator it = ca_deallocs.begin(); it != ca_deallocs.end(); ++it ) {
         std::ptr
diff _t const allocs = std::count(ca_allocs.begin(), ca_allocs.end(), *it);
         std::ptr
diff _t const deallocs = std::count(ca_deallocs.begin(), ca_deallocs.end(), *it);
-        std::printf("%d: %ld vs %ld\n", *it, allocs, deallocs);
+        std::printf("%d: %td vs %td\n", *it, allocs, deallocs);
         if (allocs != deallocs)
             return false;
     }


        


More information about the libcxx-commits mailing list