Upstream version 8.36.169.0
[platform/framework/web/crosswalk.git] / src / third_party / libc++ / trunk / test / containers / sequences / vector / vector.modifiers / push_back_exception_safety.pass.cpp
index cd81e60..f232743 100644 (file)
@@ -19,12 +19,16 @@ static bool gCopyConstructorShouldThow = false;
 
 
 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::kStartedConstructionMagicValue = 0;
 // 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);
     }
 }