Return-Path: Delivered-To: apmail-incubator-stdcxx-dev-archive@www.apache.org Received: (qmail 75480 invoked from network); 8 Aug 2006 08:33:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 8 Aug 2006 08:33:57 -0000 Received: (qmail 74808 invoked by uid 500); 8 Aug 2006 08:33:57 -0000 Delivered-To: apmail-incubator-stdcxx-dev-archive@incubator.apache.org Received: (qmail 74750 invoked by uid 500); 8 Aug 2006 08:33:57 -0000 Mailing-List: contact stdcxx-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-dev@incubator.apache.org Received: (qmail 74732 invoked by uid 99); 8 Aug 2006 08:33:57 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Aug 2006 01:33:56 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [209.237.227.198] (HELO brutus.apache.org) (209.237.227.198) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Aug 2006 01:33:56 -0700 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 509A57141F2 for ; Tue, 8 Aug 2006 08:31:14 +0000 (GMT) Message-ID: <10886580.1155025874300.JavaMail.jira@brutus> Date: Tue, 8 Aug 2006 01:31:14 -0700 (PDT) From: "Farid Zaripov (JIRA)" To: stdcxx-dev@incubator.apache.org Subject: [jira] Created: (STDCXX-268) std::list constructors do not call destructors for created objects if exception was thrown MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 #include 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 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