You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by "Farid Zaripov (JIRA)" <ji...@apache.org> on 2006/08/08 10:31:14 UTC

[jira] Created: (STDCXX-268) std::list constructors do not call destructors for created objects if exception was thrown

std::list constructors do not call destructors for created objects if exception was thrown
------------------------------------------------------------------------------------------

                 Key: STDCXX-268
                 URL: http://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


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.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Closed: (STDCXX-268) std::list constructors do not call destructors for created objects if exception was thrown

Posted by "Farid Zaripov (JIRA)" <ji...@apache.org>.
     [ 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.


[jira] Resolved: (STDCXX-268) std::list constructors do not call destructors for created objects if exception was thrown

Posted by "Farid Zaripov (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/STDCXX-268?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Farid Zaripov resolved STDCXX-268.
----------------------------------

       Resolution: Fixed
    Fix Version/s: 4.2

Fixed thus: http://svn.apache.org/viewvc?view=rev&rev=507971


> 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
>             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.


[jira] Assigned: (STDCXX-268) std::list constructors do not call destructors for created objects if exception was thrown

Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/STDCXX-268?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Martin Sebor reassigned STDCXX-268:
-----------------------------------

    Assignee: Farid Zaripov

> 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
>         Assigned To: 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.