mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-23 01:18:52 +08:00
Protect tests for new/delete under libcpp-no-exceptions
Skip the tests that expect an exception be thrown and protect unreachable catch blocks. Differential Revision: https://reviews.llvm.org/D26197 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@285791 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -7,7 +7,6 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
// XFAIL: libcpp-no-exceptions
|
|
||||||
// test operator new[]
|
// test operator new[]
|
||||||
// NOTE: asan and msan will not call the new handler.
|
// NOTE: asan and msan will not call the new handler.
|
||||||
// UNSUPPORTED: sanitizer-new-delete
|
// UNSUPPORTED: sanitizer-new-delete
|
||||||
@@ -18,6 +17,8 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
#include "test_macros.h"
|
||||||
|
|
||||||
int new_handler_called = 0;
|
int new_handler_called = 0;
|
||||||
|
|
||||||
void new_handler()
|
void new_handler()
|
||||||
@@ -36,6 +37,7 @@ struct A
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||||
std::set_new_handler(new_handler);
|
std::set_new_handler(new_handler);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -51,6 +53,7 @@ int main()
|
|||||||
{
|
{
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
A* ap = new A[3];
|
A* ap = new A[3];
|
||||||
assert(ap);
|
assert(ap);
|
||||||
assert(A_constructed == 3);
|
assert(A_constructed == 3);
|
||||||
|
@@ -7,7 +7,6 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
// XFAIL: libcpp-no-exceptions
|
|
||||||
// test operator new [] (nothrow)
|
// test operator new [] (nothrow)
|
||||||
// NOTE: asan and msan will not call the new handler.
|
// NOTE: asan and msan will not call the new handler.
|
||||||
// UNSUPPORTED: sanitizer-new-delete
|
// UNSUPPORTED: sanitizer-new-delete
|
||||||
@@ -18,6 +17,8 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
#include "test_macros.h"
|
||||||
|
|
||||||
int new_handler_called = 0;
|
int new_handler_called = 0;
|
||||||
|
|
||||||
void new_handler()
|
void new_handler()
|
||||||
@@ -37,16 +38,20 @@ struct A
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::set_new_handler(new_handler);
|
std::set_new_handler(new_handler);
|
||||||
|
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||||
try
|
try
|
||||||
|
#endif TEST_HAS_NO_EXCEPTIONS
|
||||||
{
|
{
|
||||||
void*volatile vp = operator new [] (std::numeric_limits<std::size_t>::max(), std::nothrow);
|
void*volatile vp = operator new [] (std::numeric_limits<std::size_t>::max(), std::nothrow);
|
||||||
assert(new_handler_called == 1);
|
assert(new_handler_called == 1);
|
||||||
assert(vp == 0);
|
assert(vp == 0);
|
||||||
}
|
}
|
||||||
|
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
A* ap = new(std::nothrow) A[3];
|
A* ap = new(std::nothrow) A[3];
|
||||||
assert(ap);
|
assert(ap);
|
||||||
assert(A_constructed == 3);
|
assert(A_constructed == 3);
|
||||||
|
@@ -7,8 +7,6 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
// XFAIL: libcpp-no-exceptions
|
|
||||||
|
|
||||||
// test operator new
|
// test operator new
|
||||||
|
|
||||||
// asan and msan will not call the new handler.
|
// asan and msan will not call the new handler.
|
||||||
@@ -19,6 +17,8 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
#include "test_macros.h"
|
||||||
|
|
||||||
int new_handler_called = 0;
|
int new_handler_called = 0;
|
||||||
|
|
||||||
void new_handler()
|
void new_handler()
|
||||||
@@ -37,6 +37,7 @@ struct A
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||||
std::set_new_handler(new_handler);
|
std::set_new_handler(new_handler);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -52,6 +53,7 @@ int main()
|
|||||||
{
|
{
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
A* ap = new A;
|
A* ap = new A;
|
||||||
assert(ap);
|
assert(ap);
|
||||||
assert(A_constructed);
|
assert(A_constructed);
|
||||||
|
@@ -7,7 +7,6 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
// XFAIL: libcpp-no-exceptions
|
|
||||||
// test operator new (nothrow)
|
// test operator new (nothrow)
|
||||||
|
|
||||||
// asan and msan will not call the new handler.
|
// asan and msan will not call the new handler.
|
||||||
@@ -18,6 +17,8 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
#include "test_macros.h"
|
||||||
|
|
||||||
int new_handler_called = 0;
|
int new_handler_called = 0;
|
||||||
|
|
||||||
void new_handler()
|
void new_handler()
|
||||||
@@ -37,16 +38,20 @@ struct A
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::set_new_handler(new_handler);
|
std::set_new_handler(new_handler);
|
||||||
|
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||||
try
|
try
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
void* vp = operator new (std::numeric_limits<std::size_t>::max(), std::nothrow);
|
void* vp = operator new (std::numeric_limits<std::size_t>::max(), std::nothrow);
|
||||||
assert(new_handler_called == 1);
|
assert(new_handler_called == 1);
|
||||||
assert(vp == 0);
|
assert(vp == 0);
|
||||||
}
|
}
|
||||||
|
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
A* ap = new(std::nothrow) A;
|
A* ap = new(std::nothrow) A;
|
||||||
assert(ap);
|
assert(ap);
|
||||||
assert(A_constructed);
|
assert(A_constructed);
|
||||||
|
Reference in New Issue
Block a user