view gcc/testsuite/g++.old-deja/g++.law/virtual4.C @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 04ced10e8804
children
line wrap: on
line source

// { dg-do run  }
// GROUPS passed virtual-functions
#include <stdio.h>
#include <stdlib.h>

int aset = 0;
class A
{
  public:
    void Set() { SetProp(); }
    virtual void SetProp() { aset++;}
};

class B:public A
{
  public:
    void SetProp() { if (!aset) { printf ("FAIL\n"); exit (1);} aset--;}
};

int main()
{
    A a;
    B b;
    A *c=new A;
    A *d=new B;

    a.Set();
    b.Set();
    c->Set();
    d->Set();
    printf ("PASS\n");
}