public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/56166] New: std::string::clear() can allocate memory despite being marked noexcept
@ 2013-01-31 18:20 zackw at panix dot com
  2013-01-31 18:22 ` [Bug libstdc++/56166] std::string::clear() can throw " zackw at panix dot com
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: zackw at panix dot com @ 2013-01-31 18:20 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56166

             Bug #: 56166
           Summary: std::string::clear() can allocate memory despite being
                    marked noexcept
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: zackw@panix.com


The attached test case (which is regrettably large, but I haven't found a
shorter way to trigger the problem) will call terminate() when compiled with
-std=c++11, despite there being no point at which an exception should escape
main().  The problem is deep inside std::basic_string:

/usr/include/c++/4.7/bits/basic_string.h
    796       /**
    797        *  Erases the string, making it empty.
    798        */
    799       void
    800       clear() _GLIBCXX_NOEXCEPT
    801       { _M_mutate(0, this->size(), 0); }

_M_mutate can allocate memory even when it's being asked to erase the string
(presumably due to internal reference-counting -- if you take 's2' out of the
test case the crash goes away), and thus can throw bad_alloc.  In C++11 mode,
clear() is marked 'noexcept', so we wind up in terminate().


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2015-01-18 17:37 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-31 18:20 [Bug libstdc++/56166] New: std::string::clear() can allocate memory despite being marked noexcept zackw at panix dot com
2013-01-31 18:22 ` [Bug libstdc++/56166] std::string::clear() can throw " zackw at panix dot com
2013-01-31 19:25 ` redi at gcc dot gnu.org
2013-01-31 22:24 ` paolo.carlini at oracle dot com
2013-02-01  0:49 ` zackw at panix dot com
2013-02-01  8:42 ` paolo.carlini at oracle dot com
2013-02-01 11:26 ` redi at gcc dot gnu.org
2013-07-15 19:38 ` fasdfasdas at gmail dot com
2013-07-15 19:47 ` fasdfasdas at gmail dot com
2013-07-15 20:51 ` fasdfasdas at gmail dot com
2013-09-20 15:50 ` glisse at gcc dot gnu.org
2013-09-24 10:07 ` glisse at gcc dot gnu.org
2014-06-03 22:24 ` redi at gcc dot gnu.org
2015-01-18 17:37 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).