stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Farid Zaripov (JIRA)" <j...@apache.org>
Subject [jira] Closed: (STDCXX-268) std::list constructors do not call destructors for created objects if exception was thrown
Date Wed, 06 Jun 2007 10:06:26 GMT

     [ https://issues.apache.org/jira/browse/STDCXX-268?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Farid Zaripov closed STDCXX-268.
--------------------------------


The regression test added thus: http://svn.apache.org/viewvc?view=rev&rev=544793

> std::list constructors do not call destructors for created objects if exception was thrown
> ------------------------------------------------------------------------------------------
>
>                 Key: STDCXX-268
>                 URL: https://issues.apache.org/jira/browse/STDCXX-268
>             Project: C++ Standard Library
>          Issue Type: Bug
>          Components: 23. Containers
>    Affects Versions: 4.1.3
>         Environment: All
>            Reporter: Farid Zaripov
>            Assignee: Farid Zaripov
>             Fix For: 4.2
>
>
> std::list constructors do not satisfy basic exception safety requirement (no memory leaks)
since they do not call destructors for created objects if exception was thrown.
> See details here:
> http://mail-archives.apache.org/mod_mbox/incubator-stdcxx-dev/200608.mbox/%3cF92433E3D38672499C549EB615AFADA0714819@exkiv.kyiv.vdiweb.com%3e
> test.cpp:
> -----------------------
> #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[])
> {
>     typedef std::list<ListItem> List;
>     ListItem items [20];
>     List lst (20);
>     bool thrown = false;
>     throw_inx = 10;
>     try {
>         ListItem::count_ = 0;
>         List test (20);
>     } catch (...) {
>         thrown = true;
>     }
>     assert (thrown);
>     assert (0 == ListItem::count_);
>     try {
>         thrown = false;
>         ListItem::count_ = 0;
>         List test (20, items [0]);
>     } catch (...) {
>         thrown = true;
>     }
>     assert (thrown);
>     assert (0 == ListItem::count_);
>     try {
>         thrown = false;
>         ListItem::count_ = 0;
>         List test (items, items + 20);
>     } catch (...) {
>         thrown = true;
>     }
>     assert (thrown);
>     assert (0 == ListItem::count_);
>     try {
>         thrown = false;
>         ListItem::count_ = 0;
>         List test (lst.begin (), lst.end ());
>     } catch (...) {
>         thrown = true;
>     }
>     assert (thrown);
>     assert (0 == ListItem::count_);
>     try {
>         thrown = false;
>         ListItem::count_ = 0;
>         List test (lst);
>     } catch (...) {
>         thrown = true;
>     }
>     assert (thrown);
>     assert (0 == ListItem::count_);
>     return 0;
> }
> the test output:
> ---------------------
> test: /usr/src/tests/test.cpp:45: int main(int, char**): Assertion `0 == ListItem::count_'
failed.
> Aborted.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message