[libcxx] r202885 - LWG issue #2252: Add more tests for exception safety. No changes needed in the library
Marshall Clow
mclow.lists at gmail.com
Tue Mar 4 12:31:21 PST 2014
Author: marshall
Date: Tue Mar 4 14:31:21 2014
New Revision: 202885
URL: http://llvm.org/viewvc/llvm-project?rev=202885&view=rev
Log:
LWG issue #2252: Add more tests for exception safety. No changes needed in the library
Modified:
libcxx/trunk/test/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp
libcxx/trunk/test/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp
libcxx/trunk/test/containers/sequences/vector/vector.modifiers/push_back_exception_safety.pass.cpp
Modified: libcxx/trunk/test/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp?rev=202885&r1=202884&r2=202885&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp Tue Mar 4 14:31:21 2014
@@ -19,12 +19,16 @@ static bool gCopyConstructorShouldThow =
class CMyClass {
- public: CMyClass();
+ public: CMyClass(int tag);
public: CMyClass(const CMyClass& iOther);
public: ~CMyClass();
- private: int fMagicValue;
-
+ bool equal(const CMyClass &rhs) const
+ { return fTag == rhs.fTag && fMagicValue == rhs.fMagicValue; }
+ private:
+ int fMagicValue;
+ int fTag;
+
private: static int kStartedConstructionMagicValue;
private: static int kFinishedConstructionMagicValue;
};
@@ -34,15 +38,15 @@ int CMyClass::kStartedConstructionMagicV
// Value for fMagicValue when the constructor has finished running
int CMyClass::kFinishedConstructionMagicValue = 12345;
-CMyClass::CMyClass() :
- fMagicValue(kStartedConstructionMagicValue)
+CMyClass::CMyClass(int tag) :
+ fMagicValue(kStartedConstructionMagicValue), fTag(tag)
{
// Signal that the constructor has finished running
fMagicValue = kFinishedConstructionMagicValue;
}
-CMyClass::CMyClass(const CMyClass& /*iOther*/) :
- fMagicValue(kStartedConstructionMagicValue)
+CMyClass::CMyClass(const CMyClass& iOther) :
+ fMagicValue(kStartedConstructionMagicValue), fTag(iOther.fTag)
{
// If requested, throw an exception _before_ setting fMagicValue to kFinishedConstructionMagicValue
if (gCopyConstructorShouldThow) {
@@ -57,17 +61,21 @@ CMyClass::~CMyClass() {
assert(fMagicValue == kFinishedConstructionMagicValue);
}
+bool operator==(const CMyClass &lhs, const CMyClass &rhs) { return lhs.equal(rhs); }
+
int main()
{
- CMyClass instance;
+ CMyClass instance(42);
std::deque<CMyClass> vec;
vec.push_back(instance);
+ std::deque<CMyClass> vec2(vec);
gCopyConstructorShouldThow = true;
try {
vec.push_back(instance);
}
catch (...) {
+ assert(vec==vec2);
}
}
Modified: libcxx/trunk/test/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp?rev=202885&r1=202884&r2=202885&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp Tue Mar 4 14:31:21 2014
@@ -19,12 +19,16 @@ static bool gCopyConstructorShouldThow =
class CMyClass {
- public: CMyClass();
+ public: CMyClass(int tag);
public: CMyClass(const CMyClass& iOther);
public: ~CMyClass();
- private: int fMagicValue;
-
+ bool equal(const CMyClass &rhs) const
+ { return fTag == rhs.fTag && fMagicValue == rhs.fMagicValue; }
+ private:
+ int fMagicValue;
+ int fTag;
+
private: static int kStartedConstructionMagicValue;
private: static int kFinishedConstructionMagicValue;
};
@@ -34,15 +38,15 @@ int CMyClass::kStartedConstructionMagicV
// Value for fMagicValue when the constructor has finished running
int CMyClass::kFinishedConstructionMagicValue = 12345;
-CMyClass::CMyClass() :
- fMagicValue(kStartedConstructionMagicValue)
+CMyClass::CMyClass(int tag) :
+ fMagicValue(kStartedConstructionMagicValue), fTag(tag)
{
// Signal that the constructor has finished running
fMagicValue = kFinishedConstructionMagicValue;
}
-CMyClass::CMyClass(const CMyClass& /*iOther*/) :
- fMagicValue(kStartedConstructionMagicValue)
+CMyClass::CMyClass(const CMyClass& iOther) :
+ fMagicValue(kStartedConstructionMagicValue), fTag(iOther.fTag)
{
// If requested, throw an exception _before_ setting fMagicValue to kFinishedConstructionMagicValue
if (gCopyConstructorShouldThow) {
@@ -57,17 +61,21 @@ CMyClass::~CMyClass() {
assert(fMagicValue == kFinishedConstructionMagicValue);
}
+bool operator==(const CMyClass &lhs, const CMyClass &rhs) { return lhs.equal(rhs); }
+
int main()
{
- CMyClass instance;
+ CMyClass instance(42);
std::deque<CMyClass> vec;
vec.push_front(instance);
+ std::deque<CMyClass> vec2(vec);
gCopyConstructorShouldThow = true;
try {
vec.push_front(instance);
}
catch (...) {
+ assert(vec==vec2);
}
}
Modified: libcxx/trunk/test/containers/sequences/vector/vector.modifiers/push_back_exception_safety.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/vector/vector.modifiers/push_back_exception_safety.pass.cpp?rev=202885&r1=202884&r2=202885&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/vector/vector.modifiers/push_back_exception_safety.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/vector/vector.modifiers/push_back_exception_safety.pass.cpp Tue Mar 4 14:31:21 2014
@@ -19,12 +19,16 @@ static bool gCopyConstructorShouldThow =
class CMyClass {
- public: CMyClass();
+ public: CMyClass(int tag);
public: CMyClass(const CMyClass& iOther);
public: ~CMyClass();
- private: int fMagicValue;
-
+ bool equal(const CMyClass &rhs) const
+ { return fTag == rhs.fTag && fMagicValue == rhs.fMagicValue; }
+ private:
+ int fMagicValue;
+ int fTag;
+
private: static int kStartedConstructionMagicValue;
private: static int kFinishedConstructionMagicValue;
};
@@ -34,15 +38,15 @@ int CMyClass::kStartedConstructionMagicV
// Value for fMagicValue when the constructor has finished running
int CMyClass::kFinishedConstructionMagicValue = 12345;
-CMyClass::CMyClass() :
- fMagicValue(kStartedConstructionMagicValue)
+CMyClass::CMyClass(int tag) :
+ fMagicValue(kStartedConstructionMagicValue), fTag(tag)
{
// Signal that the constructor has finished running
fMagicValue = kFinishedConstructionMagicValue;
}
-CMyClass::CMyClass(const CMyClass& /*iOther*/) :
- fMagicValue(kStartedConstructionMagicValue)
+CMyClass::CMyClass(const CMyClass& iOther) :
+ fMagicValue(kStartedConstructionMagicValue), fTag(iOther.fTag)
{
// If requested, throw an exception _before_ setting fMagicValue to kFinishedConstructionMagicValue
if (gCopyConstructorShouldThow) {
@@ -57,17 +61,21 @@ CMyClass::~CMyClass() {
assert(fMagicValue == kFinishedConstructionMagicValue);
}
+bool operator==(const CMyClass &lhs, const CMyClass &rhs) { return lhs.equal(rhs); }
+
int main()
{
- CMyClass instance;
+ CMyClass instance(42);
std::vector<CMyClass> vec;
vec.push_back(instance);
+ std::vector<CMyClass> vec2(vec);
gCopyConstructorShouldThow = true;
try {
vec.push_back(instance);
}
catch (...) {
+ assert(vec==vec2);
}
}
More information about the cfe-commits
mailing list