public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/56636] New: strange interaction of dynamic_cast and unique_ptr
@ 2013-03-16 16:59 gcc-bugs at naturalcleaningcalgary dot com
  2013-03-16 17:40 ` [Bug c++/56636] " redi at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: gcc-bugs at naturalcleaningcalgary dot com @ 2013-03-16 16:59 UTC (permalink / raw)
  To: gcc-bugs


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 ()


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

end of thread, other threads:[~2015-03-19 10:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-16 16:59 [Bug c++/56636] New: strange interaction of dynamic_cast and unique_ptr gcc-bugs at naturalcleaningcalgary dot com
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

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