bb_tests.cc 806 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // { dg-do run }
  2. struct base
  3. {
  4. int total;
  5. virtual void add (int i) { total += i; }
  6. virtual void sub (int i) { total -= i; }
  7. virtual void init (void) { total = 73; }
  8. };
  9. struct derived : public base
  10. {
  11. int total;
  12. virtual void add (int i) { total += 10 * i; }
  13. virtual void sub (int i) { total -= 2 * i; }
  14. virtual void init (void) { total = 0; }
  15. };
  16. bool
  17. get_cond_value (int x)
  18. {
  19. if ((x % 3) > 0)
  20. return true;
  21. else
  22. return false;
  23. return false;
  24. }
  25. int
  26. main (int argc, char **argv)
  27. {
  28. base *a;
  29. bool cond_value = get_cond_value (10);
  30. int x;
  31. if (cond_value)
  32. a = new base ();
  33. else
  34. a = new derived ();
  35. cond_value = get_cond_value (47);
  36. x = 0;
  37. if (!cond_value)
  38. x = 17;
  39. a->init ();
  40. for ( ; x < 10; ++x)
  41. {
  42. a->add(50);
  43. a->sub(25);
  44. }
  45. }