public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/63179] New: Does not work virtuality
@ 2014-09-04 18:46 isak50 at mail dot ru
  2014-09-04 21:59 ` [Bug c++/63179] Virtuality is not working redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: isak50 at mail dot ru @ 2014-09-04 18:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63179

            Bug ID: 63179
           Summary: Does not work virtuality
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: isak50 at mail dot ru

// g++ 1.cpp -O2 -Wall -std=c++11 -Wall
#include <stdio.h>
struct Base{
    virtual void f() {printf("base\n");}
};
struct Child : Base{
    void f()override {printf("child\n");}
};
alignas(Child)
char buf[sizeof(Child)];
union Ptr{
    decltype(::buf) buf;
    Base base;
};
int main(){
    new(buf) Child;
    Ptr *ptr = reinterpret_cast<Ptr*>(buf);
    //-------------------printf: base---//
    ptr->base.f();                      //
    Base &b = ptr->base;                //
    b.f();                              // clang print "child".
    //----------------------------------//
    //-------------------printf: child--//
    Base *b2 = &ptr->base;              //
    b2->f();                            //
    //----------------------------------//
}


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

end of thread, other threads:[~2014-09-05  8:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-04 18:46 [Bug c++/63179] New: Does not work virtuality isak50 at mail dot ru
2014-09-04 21:59 ` [Bug c++/63179] Virtuality is not working redi at gcc dot gnu.org
2014-09-05  6:52 ` isak50 at mail dot ru
2014-09-05  8:42 ` rguenth 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).