public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/9221: Incorrect dynamic cast failure
@ 2003-01-07 21:46 paterno
  0 siblings, 0 replies; 2+ messages in thread
From: paterno @ 2003-01-07 21:46 UTC (permalink / raw)
  To: gcc-gnats; +Cc: wb


>Number:         9221
>Category:       c++
>Synopsis:       Incorrect dynamic cast failure
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jan 07 13:46:01 PST 2003
>Closed-Date:
>Last-Modified:
>Originator:     paterno@fnal.gov
>Release:        gcc (GCC) 3.2 20020927 (prerelease)
>Organization:
>Environment:
Cygwin 1.3.18-1, on Windows 2000.
>Description:
// The following code compiles with g++ -O0 dcast.cpp.
// The second assertion incorrectly fails.

#include <assert.h>

struct B1
{
  virtual ~B1() {}
};

struct B2
{
  virtual ~B2() {}
  virtual B2* clone() const = 0;
};

struct D : public B1, public B2
{
  D() : B1(), B2() { }
  D* clone() const { return new D; }
};

int main()
{
  D d;
  B2* p1 = &d;
  B2* pb = p1->clone();
  assert ( pb != 0 );
  D* pd = dynamic_cast<D*>(pb);
  assert ( pd != 0 );
  delete pb;
}

>How-To-Repeat:
Compile the source file with 'g++ -O0', or any other
optimization level.
>Fix:
No work-around known.
>Release-Note:
>Audit-Trail:
>Unformatted:


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

* Re: c++/9221: Incorrect dynamic cast failure
@ 2003-01-07 22:02 bangerth
  0 siblings, 0 replies; 2+ messages in thread
From: bangerth @ 2003-01-07 22:02 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, paterno, wb

Synopsis: Incorrect dynamic cast failure

State-Changed-From-To: open->closed
State-Changed-By: bangerth
State-Changed-When: Tue Jan  7 14:02:10 2003
State-Changed-Why:
    I can confirm this problem, although probably not in the
    manner you would like: the fact that the program compiled at
    all with 3.2 was the bug -- you use covariant return types 
    for the clone function. gcc3.2 did not support this, but
    accepted the code nevertheless. It works as expected
    when you change the line
      D* clone () const ...
    into
      B2* clone () const ...
    
    With the original code, you get with gcc3.2.2pre and
    3.3 CVS versions the following message:
      x.cc:15: sorry, unimplemented: adjusting pointers for covariant returns
    
    Nathan has implemented covariant return types recently for
    the 3.4 mainline (for which I can confirm that the program
    works as expected), so this will be available in the
    overnext version.
    
    Regards
      Wolfgang

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9221


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

end of thread, other threads:[~2003-01-07 22:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-07 21:46 c++/9221: Incorrect dynamic cast failure paterno
2003-01-07 22:02 bangerth

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