fork download
  1. #include <iostream>
  2. using namespace std;
  3. static void testDifferentAnd()
  4. {
  5. const int a = 1, b = 2;
  6. cout << noboolalpha << (a&b) << (a&&b) << endl;
  7. }
  8. struct A
  9. {
  10. static inline int livingInstances;
  11. A() { cout << "A::A()\n"; livingInstances++; }
  12. ~A() { cout << "A::~A()\n"; livingInstances--; }
  13. };
  14. int main() {
  15. {
  16. cout << string(10, '-') << "1:\n";
  17. testDifferentAnd();
  18. A a();
  19. }
  20. {
  21. cout << string(10, '-') << "2:\n";
  22. A a;
  23. {
  24. A a{};
  25. }
  26. }
  27. {
  28. cout << string(10, '-') << "3:\n";
  29. A a[2];
  30. {
  31. const A& a = A();
  32. }
  33. }
  34. {
  35. cout << string(10, '-') << "4:\n";
  36. A* a2 = new A();
  37. A* a3 = new A[2];
  38. }
  39. {
  40. cout << string(10, '-') << "5:\n";
  41. A* a4 = new A;
  42. A* a5 = static_cast<A*>(malloc(sizeof(A)));
  43. }
  44. cout << string(10, '-') << "6:\n";
  45. cout << A::livingInstances << endl;
  46. }
  47.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
----------1:
01
----------2:
A::A()
A::A()
A::~A()
A::~A()
----------3:
A::A()
A::A()
A::A()
A::~A()
A::~A()
A::~A()
----------4:
A::A()
A::A()
A::A()
----------5:
A::A()
----------6:
4