[Bug c++/63179] New: Does not work virtuality
isak50 at mail dot ru
gcc-bugzilla@gcc.gnu.org
Thu Sep 4 18:46:00 GMT 2014
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(); //
//----------------------------------//
}
More information about the Gcc-bugs
mailing list