public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "bruck.michael at googlemail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/56126] New: -fno-exceptions produces constructors that rely on exceptions to signal errors in operator new Date: Mon, 28 Jan 2013 04:49:00 -0000 [thread overview] Message-ID: <bug-56126-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56126 Bug #: 56126 Summary: -fno-exceptions produces constructors that rely on exceptions to signal errors in operator new Classification: Unclassified Product: gcc Version: 4.6.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: bruck.michael@googlemail.com Code generated with -fno-exceptions active does not check for nullptr on return from operator new unless throw() is specified. In code compiled with -fno-exceptions nothing can be thrown, consequently all new operators should imply throw() or a warning/error should occur when new operators without throw() are used. $ cat test.cpp #include <stdio.h> void * operator new(size_t size) //throw() { return 0; } struct foo { virtual void dummy() {} }; int main() { foo * f = new foo(); printf("f = %p\n", f); } $ gcc test.cpp -fno-exceptions -fno-rtti test.cpp: In function ‘void* operator new(size_t)’: test.cpp:5:12: warning: ‘operator new’ must not return NULL unless it is declared ‘throw()’ (or -fcheck-new is in effect) $ ./a.out Segmentation fault (core dumped) The compiler diagnostic only appears because this example is reduced and the compiler can evaluate the return value at compile time. In real-life the compiler will generate code that assumes that all new errors return as exceptions even though exceptions are disabled. The example crashes when the vtable pointer is written, likewise but not shown here the compiler calls the constructor with this == nullptr.
next reply other threads:[~2013-01-28 4:49 UTC|newest] Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top 2013-01-28 4:49 bruck.michael at googlemail dot com [this message] 2013-01-28 4:55 ` [Bug c++/56126] " pinskia at gcc dot gnu.org 2013-01-28 5:13 ` bruck.michael at googlemail dot com 2013-01-28 5:26 ` [Bug c++/56126] -fno-exceptions should activate -fcheck-new or issue diagnostic for all new operators without throw() bruck.michael at googlemail dot com 2015-01-03 18:11 ` olafvdspek at gmail dot com 2015-01-04 1:54 ` bruck.michael at googlemail dot com 2015-01-04 13:29 ` redi at gcc dot gnu.org 2015-01-04 13:43 ` redi at gcc dot gnu.org 2015-01-04 15:50 ` olafvdspek at gmail dot com 2015-01-06 13:22 ` bruck.michael at googlemail dot com 2015-01-07 0:26 ` olafvdspek at gmail dot com 2015-01-08 21:20 ` bruck.michael at googlemail dot com 2015-01-08 21:22 ` olafvdspek at gmail dot com 2015-01-09 0:46 ` redi at gcc dot gnu.org 2015-01-09 8:24 ` bruck.michael at googlemail dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-56126-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).