> -----Original Message-----
> From: Farid Zaripov [mailto:[EMAIL PROTECTED]
> Sent: Monday, August 07, 2006 12:33 PM
> To: [email protected]
> Subject: [PATCH] 23.list.iterators 23.list.cons tests with environment
>
> It seems to be list ctors is not exception safe. The test
> 23.list.cons asserts about leaks detected when exception is
> thrown during call the ctor.
>
> The list ctors calls _RWSTD_LIST_INSERT_RANGE macro which,
> if an exception was catched, calls the _C_free_buffers()
> before rethrow.
> But _C_free_buffers() just frees the memory without calling
> dtors of the successfully allocated elements. The list dtor
> calls clear() before call of _C_free_buffers().
[...]
>
> I'll write the simple test to situate this.
The test file is attached.
Farid.
#include <list>
#include <cassert>
static int throw_inx = -1;
class ListItem
{
public:
static int count_;
void test ()
{
if (throw_inx == count_)
throw count_;
++count_;
}
ListItem () { test (); }
ListItem (const ListItem&) { test (); }
~ListItem () { --count_; }
};
int ListItem::count_ = 0;
int main(int argc, char* argv[])
{
ListItem items [20];
std::list<ListItem> lst (20);
bool thrown = false;
throw_inx = 10;
try {
ListItem::count_ = 0;
std::list<ListItem> test (20);
} catch (...) {
thrown = true;
}
assert (thrown && 0 == ListItem::count_);
try {
thrown = false;
ListItem::count_ = 0;
std::list<ListItem> test (20, items [0]);
} catch (...) {
thrown = true;
}
assert (thrown && 0 == ListItem::count_);
try {
thrown = false;
ListItem::count_ = 0;
std::list<ListItem> test (items, items + 20);
} catch (...) {
thrown = true;
}
assert (thrown && 0 == ListItem::count_);
try {
thrown = false;
ListItem::count_ = 0;
std::list<ListItem> test (lst.begin (), lst.end ());
} catch (...) {
thrown = true;
}
assert (thrown && 0 == ListItem::count_);
try {
thrown = false;
ListItem::count_ = 0;
std::list<ListItem> test (lst);
} catch (...) {
thrown = true;
}
assert (thrown && 0 == ListItem::count_);
return 0;
}