public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "gcc-bugs at naturalcleaningcalgary dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/56636] New: strange interaction of dynamic_cast and unique_ptr Date: Sat, 16 Mar 2013 16:59:00 -0000 [thread overview] Message-ID: <bug-56636-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56636 Bug #: 56636 Summary: strange interaction of dynamic_cast and unique_ptr Classification: Unclassified Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: gcc-bugs@naturalcleaningcalgary.com The following program produces a segfault at the dynamic_cast. If I change std::unique_ptr<int> to int*, or if I drop the dynamic_cast, the segfault goes away. #include <memory> struct A { void F() const { F_impl(); } virtual std::unique_ptr<int> F_impl() const = 0; }; template <typename Derived> struct A_impl : virtual A { std::unique_ptr<int> F_impl() const override { dynamic_cast<const Derived &>(*this); return nullptr; } }; struct B : virtual A {}; struct C : B, A_impl<C> {}; int main() { C().F(); } $ g++ -std=c++11 -otest test.cpp && ./test.exe I am using GCC 4.7.2 under MinGW, configured with "--enable-libstdcxx-debug --enable-languages=c,c++ --build=pentium4-pc-mingw32 --disable-nls --disable-win32-registry --enable-threads". (gdb) run Starting program: c:\devel\page\build/test.exe [New Thread 2356.0xa10] Program received signal SIGSEGV, Segmentation fault. __cxxabiv1::__dynamic_cast (src_ptr=0x4031f4, src_type=0x403180, dst_type=0x403160, src2dst=4) at ../../../../gcc-4.7.2/libstdc++-v3/libsupc++/dyncast.cc:56 56 adjust_pointer <void> (src_ptr, prefix->whole_object); (gdb) bt #0 __cxxabiv1::__dynamic_cast (src_ptr=0x4031f4, src_type=0x403180, dst_type=0x403160, src2dst=4) at ../../../../gcc-4.7.2/libstdc++-v3/libsupc++/dyncast.cc:56 #1 0x00401d04 in A_impl<C>::F_impl() const () #2 0x00401cc6 in A::F() const () #3 0x00401378 in main ()
next reply other threads:[~2013-03-16 16:59 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2013-03-16 16:59 gcc-bugs at naturalcleaningcalgary dot com [this message] 2013-03-16 17:40 ` [Bug c++/56636] " redi at gcc dot gnu.org 2013-03-20 8:38 ` daniel.kruegler at googlemail dot com 2013-03-20 9:43 ` paolo.carlini at oracle dot com 2013-03-20 10:19 ` daniel.kruegler at googlemail dot com 2015-03-19 11:03 ` paolo.carlini at oracle dot com 2015-03-19 11:59 ` ktietz at gcc dot gnu.org
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-56636-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).