summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/containers
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2015-03-09 17:08:51 +0000
committerMarshall Clow <mclow.lists@gmail.com>2015-03-09 17:08:51 +0000
commitf4903afd9351ebc089c694834faa52ec4fcd1d8a (patch)
tree8b7130e2cfa46a54940c7d4750e43fd22d06ed2f /libcxx/test/std/containers
parent82f6e433acaf46613b0fbb99b14a233a507af46b (diff)
downloadbcm5719-llvm-f4903afd9351ebc089c694834faa52ec4fcd1d8a.tar.gz
bcm5719-llvm-f4903afd9351ebc089c694834faa52ec4fcd1d8a.zip
Fix an exception-safety bug in <deque>. Reference: PR#22650. Not closing the bug because there's more work to do here
llvm-svn: 231672
Diffstat (limited to 'libcxx/test/std/containers')
-rw-r--r--libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp22
-rw-r--r--libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp20
2 files changed, 41 insertions, 1 deletions
diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp
index 3e628791a9f..8ad6b53f1b5 100644
--- a/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp
+++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp
@@ -12,12 +12,12 @@
// void push_back(const value_type& x);
#include <deque>
+#include "test_allocator.h"
#include <cassert>
// Flag that makes the copy constructor for CMyClass throw an exception
static bool gCopyConstructorShouldThow = false;
-
class CMyClass {
public: CMyClass(int tag);
public: CMyClass(const CMyClass& iOther);
@@ -25,6 +25,7 @@ class CMyClass {
bool equal(const CMyClass &rhs) const
{ return fTag == rhs.fTag && fMagicValue == rhs.fMagicValue; }
+
private:
int fMagicValue;
int fTag;
@@ -66,6 +67,7 @@ bool operator==(const CMyClass &lhs, const CMyClass &rhs) { return lhs.equal(rhs
int main()
{
CMyClass instance(42);
+ {
std::deque<CMyClass> vec;
vec.push_back(instance);
@@ -74,8 +76,26 @@ int main()
gCopyConstructorShouldThow = true;
try {
vec.push_back(instance);
+ assert(false);
+ }
+ catch (...) {
+ gCopyConstructorShouldThow = false;
+ assert(vec==vec2);
+ }
+ }
+
+ {
+ typedef std::deque<CMyClass, test_allocator<CMyClass> > C;
+ C vec;
+ C vec2(vec);
+
+ C::allocator_type::throw_after = 1;
+ try {
+ vec.push_back(instance);
+ assert(false);
}
catch (...) {
assert(vec==vec2);
}
+ }
}
diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp
index 6ae06db0bca..e01b2a224ff 100644
--- a/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp
+++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp
@@ -13,6 +13,7 @@
#include <deque>
#include <cassert>
+#include "test_allocator.h"
// Flag that makes the copy constructor for CMyClass throw an exception
static bool gCopyConstructorShouldThow = false;
@@ -66,6 +67,7 @@ bool operator==(const CMyClass &lhs, const CMyClass &rhs) { return lhs.equal(rhs
int main()
{
CMyClass instance(42);
+ {
std::deque<CMyClass> vec;
vec.push_front(instance);
@@ -74,8 +76,26 @@ int main()
gCopyConstructorShouldThow = true;
try {
vec.push_front(instance);
+ assert(false);
}
catch (...) {
+ gCopyConstructorShouldThow = false;
assert(vec==vec2);
}
+ }
+
+ {
+ typedef std::deque<CMyClass, test_allocator<CMyClass> > C;
+ C vec;
+ C vec2(vec);
+
+ C::allocator_type::throw_after = 1;
+ try {
+ vec.push_front(instance);
+ assert(false);
+ }
+ catch (...) {
+ assert(vec==vec2);
+ }
+ }
}
OpenPOWER on IntegriCloud