view gcc/testsuite/g++.dg/ubsan/vptr-11.C @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
line wrap: on
line source

// PR c++/70147
// { dg-do run }
// { dg-options "-fsanitize=vptr -fno-sanitize-recover=vptr" }

static int ac, ad, bc, bd, cc, cd, dc, dd;
struct A
{
  A ()
  {
    ac++;
  }
  virtual void f ()
  {
  }
  __attribute__ ((noinline)) ~ A ();
};

struct D
{
  __attribute__ ((noinline)) D (int);
  ~D ()
  {
    dd++;
  }
};
struct B: virtual A, D
{
  B ():D (1)
  {
    bc++;
  }
  virtual void f ()
  {
  }
  ~B ()
  {
    bd++;
  }
};

struct C: B, virtual A
{
  C ()
  {
    cc++;
  }
  ~C ()
  {
    cd++;
  }
};

D::D (int x)
{
  if (x)
    throw 1;
  dc++;
}

__attribute__ ((noinline, noclone))
void foo (A * p)
{
  p->f ();
}

A::~A ()
{
  foo (this);
  ad++;
}

int
main ()
{
  try
    {
      C c;
    }
  catch ( ...)
    {
    }
  if (ac != 1 || ad != 1 || bc || bd || cc || cd || dc || dd)
    __builtin_abort ();
}