chain-implicit-definition.cpp 780 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // no PCH
  2. // RUN: %clang_cc1 -emit-llvm-only -include %s -include %s %s
  3. // with PCH
  4. // RUN: %clang_cc1 -emit-llvm-only -chain-include %s -chain-include %s %s
  5. #if !defined(PASS1)
  6. #define PASS1
  7. // A base with a virtual dtor.
  8. struct A {
  9. virtual ~A();
  10. };
  11. // A derived class with an implicit virtual dtor.
  12. struct B : A {
  13. // Key function to suppress vtable definition.
  14. virtual void virt();
  15. };
  16. #elif !defined(PASS2)
  17. #define PASS2
  18. // Further derived class that requires ~B().
  19. // Causes definition of ~B(), but it was lost when saving PCH.
  20. struct C : B {
  21. C();
  22. ~C() {}
  23. };
  24. #else
  25. void foo() {
  26. // Variable that requires ~C().
  27. C c;
  28. }
  29. // VTable placement would again cause definition of ~B(), hiding the bug,
  30. // if not for B::virt(), which suppresses the placement.
  31. #endif