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

Stephan T. Lavavej via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 3 16:53:32 PST 2017


Author: stl_msft
Date: Tue Jan  3 18:53:31 2017
New Revision: 290921

URL: http://llvm.org/viewvc/llvm-project?rev=290921&view=rev
Log:
[libcxx] [test] Fix recently introduced warnings emitted by MSVC.

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.

Fixes D27785.

Modified:
    libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp
    libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp
    libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp
    libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp

Modified: libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp?rev=290921&r1=290920&r2=290921&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp Tue Jan  3 18:53:31 2017
@@ -42,6 +42,7 @@ void test_no_inner_alloc()
         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 @@ void test_no_inner_alloc()
         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 @@ void test_with_inner_alloc()
         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 @@ void test_with_inner_alloc()
         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);

Modified: libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp?rev=290921&r1=290920&r2=290921&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp Tue Jan  3 18:53:31 2017
@@ -42,6 +42,7 @@ void test_no_inner_alloc()
         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 @@ void test_no_inner_alloc()
         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 @@ void test_with_inner_alloc()
         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 @@ void test_with_inner_alloc()
         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);

Modified: libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp?rev=290921&r1=290920&r2=290921&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp Tue Jan  3 18:53:31 2017
@@ -42,6 +42,7 @@ void test_no_inner_alloc()
         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 @@ void test_no_inner_alloc()
         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 @@ void test_with_inner_alloc()
         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 @@ void test_with_inner_alloc()
         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);

Modified: libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp?rev=290921&r1=290920&r2=290921&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp Tue Jan  3 18:53:31 2017
@@ -41,6 +41,7 @@ void test_no_inner_alloc()
         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 @@ void test_no_inner_alloc()
         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 @@ void test_with_inner_alloc()
         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 @@ void test_with_inner_alloc()
         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);




More information about the cfe-commits mailing list