fork(3) download
  1. #include <cstddef>
  2. #include <new>
  3. #include <iostream>
  4. #include <initializer_list>
  5.  
  6. class Allocator {
  7. public:
  8. static Allocator createOnStack() {
  9. return {};
  10. }
  11. ~Allocator() {
  12. std::cout << "Destructed " << --i << std::endl;
  13. }
  14.  
  15. protected:
  16. Allocator() {
  17. std::cout << "Created " << i++ << std::endl;
  18. }
  19. Allocator(const Allocator&) = delete;
  20. static int i;
  21. };
  22.  
  23. int Allocator::i = 0;
  24.  
  25. Allocator g() {
  26. Allocator&& a = Allocator::createOnStack();
  27. //return a;
  28. }
  29.  
  30. void f() {
  31. }
  32.  
  33. Allocator&& global = Allocator::createOnStack();
  34.  
  35. int main() {
  36. Allocator&& a = Allocator::createOnStack();
  37. const Allocator& b = Allocator::createOnStack();
  38. return 0;
  39. //Allocator* b = new Allocator{Allocator::createOnStack()};
  40. //Allocator* c = ::new (nullptr) Allocator;
  41. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Created 0
Created 1
Created 2
Destructed 2
Destructed 1
Destructed 0