STL_MSFT created this revision.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.

[libcxx] [test] Fix recently introduced warnings emitted by MSVC.

test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp
test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp
test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp
test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp
These tests were using malloc()'s return value without checking for null,
which MSVC's /analyze rightly warns about. Asserting that the pointer is
non-null both expresses the test's intention and silences the warning.

test/support/controlled_allocators.hpp
Fix two unreferenced parameters by removing their names, and one unused 
variable by void-casting it.

test/support/uses_alloc_types.hpp
Fix an unreferenced function parameter pack by removing its name.


https://reviews.llvm.org/D27785

Files:
  
test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp
  
test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp
  
test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp
  
test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp
  test/support/controlled_allocators.hpp
  test/support/uses_alloc_types.hpp

Index: test/support/uses_alloc_types.hpp
===================================================================
--- test/support/uses_alloc_types.hpp
+++ test/support/uses_alloc_types.hpp
@@ -372,7 +372,7 @@
         : Base(&makeArgumentID<NotUsesAllocator &&>()) {}
     // Non-Uses Allocator Ctor
     template <class ...Args, EnableIfB<sizeof...(Args) == Arity> = false>
-    NotUsesAllocator(Args&&... args) : Base(&makeArgumentID<Args&&...>()) {}
+    NotUsesAllocator(Args&&...) : Base(&makeArgumentID<Args&&...>()) {}
 
     // Uses Allocator Arg Ctor
     template <class ...Args>
Index: test/support/controlled_allocators.hpp
===================================================================
--- test/support/controlled_allocators.hpp
+++ test/support/controlled_allocators.hpp
@@ -117,16 +117,16 @@
     }
 
     template <class ...Args, class Alloc, class Tp>
-    void countConstruct(Alloc const& a, Tp *p) {
+    void countConstruct(Alloc const&, Tp *p) {
       ++construct_called;
       last_construct_pointer = p;
       last_construct_alloc = &makeTypeID<Alloc>();
       last_construct_type = &makeTypeID<Tp>();
       last_construct_args = &makeArgumentID<Args...>();
     }
 
     template <class Alloc, class Tp>
-    void countDestroy(Alloc const& a, Tp *p) {
+    void countDestroy(Alloc const&, Tp *p) {
       ++destroy_called;
       last_destroy_alloc = &makeTypeID<Alloc>();
       last_destroy_type = &makeTypeID<Tp>();
@@ -264,6 +264,7 @@
     template <class U, class ...Args>
     void construct(U *p, Args&&... args) {
       auto *c = ::new ((void*)p) U(std::forward<Args>(args)...);
+      ((void)c); // Prevent unused warning
       P->countConstruct<Args&&...>(*this, p);
     }
 
Index: test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp
===================================================================
--- test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp
+++ test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp
@@ -41,6 +41,7 @@
         using SA = std::scoped_allocator_adaptor<Alloc>;
         static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, "");
         Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+        assert(ptr != nullptr);
         Alloc CA(P);
         SA A(CA);
         A.construct(ptr, x, std::move(y));
@@ -65,6 +66,7 @@
         using SA = std::scoped_allocator_adaptor<Alloc>;
         static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, "");
         Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+        assert(ptr != nullptr);
         Alloc CA(P);
         SA A(CA);
         A.construct(ptr, std::move(x), y);
@@ -99,6 +101,7 @@
         static_assert(!std::uses_allocator<T, Outer>::value, "");
         static_assert(std::uses_allocator<T, Inner>::value, "");
         Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+        assert(ptr != nullptr);
         Outer O(POuter);
         Inner I(PInner);
         SA A(O, I);
@@ -127,6 +130,7 @@
         static_assert(!std::uses_allocator<T, Outer>::value, "");
         static_assert(std::uses_allocator<T, Inner>::value, "");
         Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+        assert(ptr != nullptr);
         Outer O(POuter);
         Inner I(PInner);
         SA A(O, I);
Index: test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp
===================================================================
--- test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp
+++ test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp
@@ -42,6 +42,7 @@
         using SA = std::scoped_allocator_adaptor<Alloc>;
         static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, "");
         Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+        assert(ptr != nullptr);
         Alloc CA(P);
         SA A(CA);
         PairIn in(x, std::move(y));
@@ -68,6 +69,7 @@
         using SA = std::scoped_allocator_adaptor<Alloc>;
         static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, "");
         Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+        assert(ptr != nullptr);
         Alloc CA(P);
         SA A(CA);
         PairIn in(x, y);
@@ -104,6 +106,7 @@
         static_assert(!std::uses_allocator<T, Outer>::value, "");
         static_assert(std::uses_allocator<T, Inner>::value, "");
         Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+        assert(ptr != nullptr);
         Outer O(POuter);
         Inner I(PInner);
         SA A(O, I);
@@ -134,6 +137,7 @@
         static_assert(!std::uses_allocator<T, Outer>::value, "");
         static_assert(std::uses_allocator<T, Inner>::value, "");
         Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+        assert(ptr != nullptr);
         Outer O(POuter);
         Inner I(PInner);
         SA A(O, I);
Index: test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp
===================================================================
--- test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp
+++ test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp
@@ -42,6 +42,7 @@
         using SA = std::scoped_allocator_adaptor<Alloc>;
         static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, "");
         Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+        assert(ptr != nullptr);
         Alloc CA(P);
         SA A(CA);
         A.construct(ptr, std::piecewise_construct,
@@ -68,6 +69,7 @@
         using SA = std::scoped_allocator_adaptor<Alloc>;
         static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, "");
         Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+        assert(ptr != nullptr);
         Alloc CA(P);
         SA A(CA);
         A.construct(ptr, std::piecewise_construct,
@@ -104,6 +106,7 @@
         static_assert(!std::uses_allocator<T, Outer>::value, "");
         static_assert(std::uses_allocator<T, Inner>::value, "");
         Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+        assert(ptr != nullptr);
         Outer O(POuter);
         Inner I(PInner);
         SA A(O, I);
@@ -134,6 +137,7 @@
         static_assert(!std::uses_allocator<T, Outer>::value, "");
         static_assert(std::uses_allocator<T, Inner>::value, "");
         Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+        assert(ptr != nullptr);
         Outer O(POuter);
         Inner I(PInner);
         SA A(O, I);
Index: test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp
===================================================================
--- test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp
+++ test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp
@@ -42,6 +42,7 @@
         using SA = std::scoped_allocator_adaptor<Alloc>;
         static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, "");
         Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+        assert(ptr != nullptr);
         Alloc CA(P);
         SA A(CA);
         const PairIn in(x, std::move(y));
@@ -68,6 +69,7 @@
         using SA = std::scoped_allocator_adaptor<Alloc>;
         static_assert(std::uses_allocator<T, CountingAllocator<T> >::value, "");
         Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+        assert(ptr != nullptr);
         Alloc CA(P);
         SA A(CA);
         const PairIn in(x, y);
@@ -104,6 +106,7 @@
         static_assert(!std::uses_allocator<T, Outer>::value, "");
         static_assert(std::uses_allocator<T, Inner>::value, "");
         Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+        assert(ptr != nullptr);
         Outer O(POuter);
         Inner I(PInner);
         SA A(O, I);
@@ -134,6 +137,7 @@
         static_assert(!std::uses_allocator<T, Outer>::value, "");
         static_assert(std::uses_allocator<T, Inner>::value, "");
         Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+        assert(ptr != nullptr);
         Outer O(POuter);
         Inner I(PInner);
         SA A(O, I);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to