1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: libcpp-no-exceptions
13 // void push_front(const value_type& x);
18 // Flag that makes the copy constructor for CMyClass throw an exception
19 static bool gCopyConstructorShouldThow = false;
24 public: CMyClass(const CMyClass& iOther);
27 private: int fMagicValue;
29 private: static int kStartedConstructionMagicValue;
30 private: static int kFinishedConstructionMagicValue;
33 // Value for fMagicValue when the constructor has started running, but not yet finished
34 int CMyClass::kStartedConstructionMagicValue = 0;
35 // Value for fMagicValue when the constructor has finished running
36 int CMyClass::kFinishedConstructionMagicValue = 12345;
38 CMyClass::CMyClass() :
39 fMagicValue(kStartedConstructionMagicValue)
41 // Signal that the constructor has finished running
42 fMagicValue = kFinishedConstructionMagicValue;
45 CMyClass::CMyClass(const CMyClass& /*iOther*/) :
46 fMagicValue(kStartedConstructionMagicValue)
48 // If requested, throw an exception _before_ setting fMagicValue to kFinishedConstructionMagicValue
49 if (gCopyConstructorShouldThow) {
50 throw std::exception();
52 // Signal that the constructor has finished running
53 fMagicValue = kFinishedConstructionMagicValue;
56 CMyClass::~CMyClass() {
57 // Only instances for which the constructor has finished running should be destructed
58 assert(fMagicValue == kFinishedConstructionMagicValue);
64 std::list<CMyClass> vec;
66 vec.push_front(instance);
68 gCopyConstructorShouldThow = true;
70 vec.push_front(instance);