dup_name.cc 849 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // { dg-do run }
  2. #include <assert.h>
  3. extern "C" int printf(const char *, ...);
  4. class Subscriptor
  5. {
  6. public:
  7. Subscriptor()
  8. { counter = 1;}
  9. virtual ~Subscriptor()
  10. {
  11. counter--;
  12. assert(counter == 0);
  13. }
  14. private:
  15. static int counter;
  16. };
  17. int Subscriptor::counter;
  18. template <typename number>
  19. class Polynomial : public Subscriptor
  20. {
  21. };
  22. class LagrangeEquidistant: public Polynomial<double>
  23. {
  24. };
  25. template <int value>
  26. class A
  27. {
  28. public:
  29. class Nested: public LagrangeEquidistant
  30. {
  31. };
  32. A() { n = new Nested; }
  33. ~A() { delete n; }
  34. Subscriptor * n;
  35. };
  36. template<typename _Tp>
  37. inline void
  38. _MyDestroy(_Tp* __pointer)
  39. { __pointer->~_Tp(); }
  40. int main()
  41. {
  42. Subscriptor * s1 = new LagrangeEquidistant;
  43. _MyDestroy(s1);
  44. A<1> * a1 = new A<1>;
  45. _MyDestroy(a1);
  46. A<2> * a2 = new A<2>;
  47. _MyDestroy(a2);
  48. return 0;
  49. }