[libcxx] r245522 - Cleanup failing dynarray tests

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 19 16:33:18 PDT 2015


Author: ericwf
Date: Wed Aug 19 18:33:18 2015
New Revision: 245522

URL: http://llvm.org/viewvc/llvm-project?rev=245522&view=rev
Log:
Cleanup failing dynarray tests

Added:
    libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default_throws_bad_alloc.pass.cpp
Modified:
    libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp

Modified: libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp?rev=245522&r1=245521&r2=245522&view=diff
==============================================================================
--- libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp (original)
+++ libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp Wed Aug 19 18:33:18 2015
@@ -7,6 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+// UNSUPPORTED: c++98, c++03, c++11
+
 // dynarray.cons
 
 // explicit dynarray(size_type c);
@@ -16,22 +18,21 @@
 
 // ~dynarray();
 
-  
-#include <__config>
-
-#if _LIBCPP_STD_VER > 11
 
 #include <experimental/dynarray>
 #include <cassert>
 
 #include <algorithm>
 #include <complex>
+#include <limits>
+#include <new>
 #include <string>
 
+
 using std::experimental::dynarray;
 
 template <class T>
-void test ( const std::initializer_list<T> &vals ) {
+void testInitList( const std::initializer_list<T> &vals ) {
     typedef dynarray<T> dynA;
     
     dynA d1 ( vals );
@@ -41,12 +42,14 @@ void test ( const std::initializer_list<
 
 
 template <class T>
-void test ( const T &val ) {
+void test ( const T &val, bool DefaultValueIsIndeterminate = false) {
     typedef dynarray<T> dynA;
     
     dynA d1 ( 4 );
     assert ( d1.size () == 4 );
-    assert ( std::all_of ( d1.begin (), d1.end (), []( const T &item ){ return item == T(); } ));
+    if (!DefaultValueIsIndeterminate) {
+        assert ( std::all_of ( d1.begin (), d1.end (), []( const T &item ){ return item == T(); } ));
+    }
 
     dynA d2 ( 7, val );
     assert ( d2.size () == 7 );
@@ -60,27 +63,23 @@ void test ( const T &val ) {
 void test_bad_length () {
     try { dynarray<int> ( std::numeric_limits<size_t>::max() / sizeof ( int ) + 1 ); }
     catch ( std::bad_array_length & ) { return ; }
+    catch (...) { assert(false); }
     assert ( false );
-    }
+}
 
-void test_bad_alloc () {
-    try { dynarray<int> ( std::numeric_limits<size_t>::max() / sizeof ( int ) - 1 ); }
-    catch ( std::bad_alloc & ) { return ; }
-    assert ( false );
-    }
 
 int main()
 {
-//  test<int> ( 14 );       // ints don't get default initialized
-    test<long> ( 0 );
-    test<double> ( 14.0 );
+    test<int> ( 14, /* DefaultValueIsIndeterminate */ true );       // ints don't get default initialized
+    test<long> ( 0, true);
+    test<double> ( 14.0, true );
     test<std::complex<double>> ( std::complex<double> ( 14, 0 ));
     test<std::string> ( "fourteen" );
     
-    test ( { 1, 1, 2, 3, 5, 8 } );
-    test ( { 1., 1., 2., 3., 5., 8. } );
-    test ( { std::string("1"), std::string("1"), std::string("2"), std::string("3"), 
-                std::string("5"), std::string("8")} );
+    testInitList( { 1, 1, 2, 3, 5, 8 } );
+    testInitList( { 1., 1., 2., 3., 5., 8. } );
+    testInitList( { std::string("1"), std::string("1"), std::string("2"), std::string("3"),
+                  std::string("5"), std::string("8")} );
     
 //  Make sure we don't pick up the Allocator version here
     dynarray<long> d1 ( 20, 3 );
@@ -88,8 +87,4 @@ int main()
     assert ( std::all_of ( d1.begin (), d1.end (), []( long item ){ return item == 3L; } ));
 
     test_bad_length ();
-    test_bad_alloc ();
 }
-#else
-int main() {}
-#endif

Added: libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default_throws_bad_alloc.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default_throws_bad_alloc.pass.cpp?rev=245522&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default_throws_bad_alloc.pass.cpp (added)
+++ libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default_throws_bad_alloc.pass.cpp Wed Aug 19 18:33:18 2015
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// dynarray.cons
+
+// explicit dynarray(size_type c);
+
+// UNSUPPORTED: c++98, c++03, c++11
+
+// The sanitizers replace new/delete with versions that do not throw bad_alloc.
+// UNSUPPORTED: sanitizer-new-delete, ubsan
+
+
+#include <experimental/dynarray>
+#include <limits>
+#include <new>
+#include <cassert>
+
+
+using std::experimental::dynarray;
+
+int main() {
+    try { dynarray<int>((std::numeric_limits<size_t>::max() / sizeof(int)) - 1); }
+    catch (std::bad_alloc &) { return 0; }
+    catch (...) { assert(false); }
+    assert(false);
+}




More information about the cfe-commits mailing list