home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progc / fixed300.arj / BUG16.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-26  |  564 b   |  29 lines

  1. #if 0
  2. From:
  3. Subject: Destructors not called right in || && expressions
  4. Status: Works in ZTC++ 2.18
  5. #endif
  6.  
  7. // bug16.cpp
  8. // cfront: Sorry, not implemented...
  9. // Turbo C++: Calls constructor once, destructor 3 times
  10. // Zortech: Calls constructor once, destructor twice
  11.  
  12. #include <stdio.h>
  13.  
  14. struct X
  15. {
  16.   X(int x)    { printf("X(%d)\n",x); }
  17.   ~X()        { printf("~X()\n"); } 
  18. };
  19.  
  20. int f(X x) {return 0;}
  21.  
  22. void main()
  23. {
  24.   1 && f(3);  // Calls X(3) and ~X()
  25.   0 && f(3);  // bug: calls destructor only
  26.   1 || f(3);  // bug: calls destructor only
  27. }
  28.  
  29.