Fix type in the changelog entry,
[official-gcc.git] / gcc / testsuite / g++.dg / ipa / devirt-33.C
blob970a96b88d8ed9a6dec31eaa8980ac8ef46e41cf
1 /* Verify we do not devirtualize wrongly to __cxa_pure_virtual */
3 /* { dg-do run } */
4 /* { dg-options "-O2 -std=c++11"  } */
7 inline void* operator new(__SIZE_TYPE__ s, void* buf) throw() {
8    return buf;
9
11 class A {
13 private:
14   struct Base {
15       virtual ~Base() {}
16       virtual Base *Clone(void *buf) const = 0;
17       virtual float *Allocate(__SIZE_TYPE__ count) = 0;
18    };
20  struct Value : Base {
21     virtual ~Value (){}
22     Base *Clone(void* buf)  const override {
23       return new (buf) Value(); 
24     } 
26     float *Allocate(__SIZE_TYPE__ count) override {
27       return new float[count];
28     }
29   };
31 public:
32   A() {
33     new (buffer_) Value();
34   }
35   A(const A& other) {
36     other.ptr()->Clone(buffer_);
37   }
39   float *Allocate() {
40      return ptr()->Allocate(100);
41   }
42   const Base *ptr() const { return reinterpret_cast<const Base*>(buffer_);}
43   Base *ptr()  { return reinterpret_cast< Base*>(buffer_);}
45 private:
46   alignas(16) char buffer_[1024];
50 struct B {
51  B (const A& a) : a_(a) {
52     buff_ = a_.Allocate();
53  }
55  float *buff_;
56  A a_;
59 struct Dummy {
60  int i;
63 struct D : public Dummy {
64    __attribute__((noinline)) D( const A&a);
66   B b_;
69 D::D(const A&a) : b_(a) {}
71 int main()
73    A a;
74    D d(a); 
76    return 0;