public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52972] New: [4.6] Pure virtual method is called instead of child's method
@ 2012-04-13 11:33 drinob at gmail dot com
  2012-04-13 16:24 ` [Bug c++/52972] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: drinob at gmail dot com @ 2012-04-13 11:33 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52972

             Bug #: 52972
           Summary: [4.6] Pure virtual method is called instead of child's
                    method
    Classification: Unclassified
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: drinob@gmail.com


Created attachment 27150
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27150
Bug sample

drino@netbook:~/src$ g++ test.cpp
drino@netbook:~/src$ ./a.out 
pure virtual method called
terminate called without an active exception
Aborted


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

* [Bug c++/52972] Pure virtual method is called instead of child's method
  2012-04-13 11:33 [Bug c++/52972] New: [4.6] Pure virtual method is called instead of child's method drinob at gmail dot com
@ 2012-04-13 16:24 ` pinskia at gcc dot gnu.org
  2012-04-13 16:28 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-04-13 16:24 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52972

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-04-13 16:24:07 UTC ---
I think you are getting the correct behavior as the vtable for the base class
is the current vtable for this.

And "        return static_cast < Real* > (this);"  Does not change the vtable
of the return class.


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

* [Bug c++/52972] Pure virtual method is called instead of child's method
  2012-04-13 11:33 [Bug c++/52972] New: [4.6] Pure virtual method is called instead of child's method drinob at gmail dot com
  2012-04-13 16:24 ` [Bug c++/52972] " pinskia at gcc dot gnu.org
@ 2012-04-13 16:28 ` redi at gcc dot gnu.org
  2012-04-13 16:28 ` drinob at gmail dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2012-04-13 16:28 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52972

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-04-13 16:27:44 UTC ---
right, during the base constructor the derived class hasn't been constructed
yet and you can't call its virtual functions


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

* [Bug c++/52972] Pure virtual method is called instead of child's method
  2012-04-13 11:33 [Bug c++/52972] New: [4.6] Pure virtual method is called instead of child's method drinob at gmail dot com
  2012-04-13 16:24 ` [Bug c++/52972] " pinskia at gcc dot gnu.org
  2012-04-13 16:28 ` redi at gcc dot gnu.org
@ 2012-04-13 16:28 ` drinob at gmail dot com
  2012-04-13 16:35 ` drinob at gmail dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: drinob at gmail dot com @ 2012-04-13 16:28 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52972

--- Comment #3 from drinob at gmail dot com 2012-04-13 16:28:36 UTC ---
Yes, this is my mistake.


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

* [Bug c++/52972] Pure virtual method is called instead of child's method
  2012-04-13 11:33 [Bug c++/52972] New: [4.6] Pure virtual method is called instead of child's method drinob at gmail dot com
                   ` (2 preceding siblings ...)
  2012-04-13 16:28 ` drinob at gmail dot com
@ 2012-04-13 16:35 ` drinob at gmail dot com
  2012-04-13 17:28 ` redi at gcc dot gnu.org
  2012-04-13 17:44 ` drinob at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: drinob at gmail dot com @ 2012-04-13 16:35 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52972

--- Comment #4 from drinob at gmail dot com 2012-04-13 16:35:35 UTC ---
But it seems to work in g++ 4.3 (which is used at ideone.com):
http://ideone.com/zy5R4
Is that behavior uncorrect?


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

* [Bug c++/52972] Pure virtual method is called instead of child's method
  2012-04-13 11:33 [Bug c++/52972] New: [4.6] Pure virtual method is called instead of child's method drinob at gmail dot com
                   ` (3 preceding siblings ...)
  2012-04-13 16:35 ` drinob at gmail dot com
@ 2012-04-13 17:28 ` redi at gcc dot gnu.org
  2012-04-13 17:44 ` drinob at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2012-04-13 17:28 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52972

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-04-13 17:27:33 UTC ---
The standard says "Member functions can be called from a constructor (or
destructor) of an abstract class; the effect of making a virtual call to a pure
virtual function directly or indirectly for the object being created (or
destroyed) from such a constructor (or destructor) is undefined."

The program has undefined behaviour, there is no correct or incorrect behaviour
for the compiler. Whatever the compiler does with your program does is valid. 
Including setting fire to your computer.


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

* [Bug c++/52972] Pure virtual method is called instead of child's method
  2012-04-13 11:33 [Bug c++/52972] New: [4.6] Pure virtual method is called instead of child's method drinob at gmail dot com
                   ` (4 preceding siblings ...)
  2012-04-13 17:28 ` redi at gcc dot gnu.org
@ 2012-04-13 17:44 ` drinob at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: drinob at gmail dot com @ 2012-04-13 17:44 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52972

--- Comment #6 from drinob at gmail dot com 2012-04-13 17:43:44 UTC ---
Thank you for your explanation. Now it's all clear.


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

end of thread, other threads:[~2012-04-13 17:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-13 11:33 [Bug c++/52972] New: [4.6] Pure virtual method is called instead of child's method drinob at gmail dot com
2012-04-13 16:24 ` [Bug c++/52972] " pinskia at gcc dot gnu.org
2012-04-13 16:28 ` redi at gcc dot gnu.org
2012-04-13 16:28 ` drinob at gmail dot com
2012-04-13 16:35 ` drinob at gmail dot com
2012-04-13 17:28 ` redi at gcc dot gnu.org
2012-04-13 17:44 ` drinob at gmail dot com

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