From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27672 invoked by alias); 16 Mar 2013 16:59:36 -0000 Received: (qmail 27606 invoked by uid 48); 16 Mar 2013 16:59:09 -0000 From: "gcc-bugs at naturalcleaningcalgary dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gcc-bugs at naturalcleaningcalgary dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2013-03/txt/msg01184.txt.bz2 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 to int*, or if I drop the dynamic_cast, the segfault goes away. #include struct A { void F() const { F_impl(); } virtual std::unique_ptr F_impl() const = 0; }; template struct A_impl : virtual A { std::unique_ptr F_impl() const override { dynamic_cast(*this); return nullptr; } }; struct B : virtual A {}; struct C : B, A_impl {}; 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 (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::F_impl() const () #2 0x00401cc6 in A::F() const () #3 0x00401378 in main ()