From c651afce8af211a080d5641f1328732af4c54960 Mon Sep 17 00:00:00 2001 From: Michael Stevens Date: Thu, 7 Oct 2004 08:03:11 +0000 Subject: [PATCH] add placement_new test svn path=/trunk/boost/libs/numeric/ublas/; revision=25603 --- Jamfile | 3 +++ Jamfile.v2 | 4 +++- test/placement_new.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 test/placement_new.cpp diff --git a/Jamfile b/Jamfile index ee6614cb..ac0f4125 100644 --- a/Jamfile +++ b/Jamfile @@ -116,6 +116,9 @@ test-suite numeric/uBLAS # $(UBLAS_TESTSET) # <*>"BOOST_UBLAS_NO_ELEMENT_PROXIES" # ] + + [ run test/placement_new.cpp + ] [ compile concepts.cpp : # requirements EXTERNAL diff --git a/Jamfile.v2 b/Jamfile.v2 index 245956d3..48c20cb7 100644 --- a/Jamfile.v2 +++ b/Jamfile.v2 @@ -49,7 +49,6 @@ test-suite numeric/uBLAS : # input files : # requirements $(UBLAS_TESTSET) - intel-linux:"-fpstkchk" # Try and pick up runtime failures vacpp:"BOOST_UBLAS_NO_ELEMENT_PROXIES" ] [ run test2/test2.cpp @@ -100,6 +99,9 @@ test-suite numeric/uBLAS # $(UBLAS_TESTSET) # vacpp:"BOOST_UBLAS_NO_ELEMENT_PROXIES" # ] + + [ run test/placement_new.cpp + ] [ compile concepts.cpp : # requirements EXTERNAL diff --git a/test/placement_new.cpp b/test/placement_new.cpp new file mode 100644 index 00000000..b7d69149 --- /dev/null +++ b/test/placement_new.cpp @@ -0,0 +1,54 @@ +/* + * Test placement new and array placement new for uBLAS + * See if base pointer is effected by array count cookie + */ + +#include +#include + +// User defined type to capture base pointer on construction +class udt; +udt* base_pointer; + +class udt { +public: + udt () { + base_pointer = this; + } + ~udt () {} // required for GCC prior to 3.4 to generate cookie +}; + + +int main () +{ + udt a; + udt* ap = &a; + + // Capture placement new offsets for a udt + new (ap) udt; + int new_offset = int (base_pointer - ap); + new (ap) udt [1]; + int array_new_offset = int (base_pointer - ap); + + // Print offsets - we expect 0,0 or 0,sizeof(std::size_t) + std::cout << new_offset <<','<< array_new_offset << std::endl; + + // Return status + if (new_offset != 0) + return -1; // Very bad if new has an offset + +#ifdef BOOST_UBLAS_USEFUL_ARRAY_PLACEMENT_NEW + bool expect_array_offset = false; +#else + bool expect_array_offset = true; +#endif + // Check match between config and array + if (!expect_array_offset && array_new_offset != 0) { + return -2; // Bad config should not enable array new + } + if (expect_array_offset && array_new_offset == 0) { + return -3; // Config could enable array new + } + + return 0; +}