Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!swrinde!ucsd!nosc!logicon.com!trantor.harris-atd.com!jedi!mvm From: mvm@jedi.harris-atd.com (Matt Mahoney) Newsgroups: comp.lang.c++ Subject: Bug: temporary object in && expression Message-ID: <4197@trantor.harris-atd.com> Date: 27 Aug 90 15:11:50 GMT Sender: news@trantor.harris-atd.com Reply-To: mvm@jedi.UUCP (Matt Mahoney) Distribution: comp.lang.c++ Organization: CAE Design Center, Harris Corp., Melbourne, Fl. Lines: 31 Does anyone know of a C++ compiler that handles code like: String s; if (s == "something" || s == "something else") // error Turbo C++ 1.0, Zortech 2.1, and Sun C++ 2.0 (a cfront port) all fail to handle temporary objects with destructors in && or || expressions. Here is a more complete example: // cfront: Sorry, not implemented... // Turbo C++: Calls constructor once, destructor 3 times // Zortech: Calls constructor once, destructor twice struct X { X(int x) {cout << "X(" << x << ")\n";} ~X() {cout << "~X()\n";} }; int f(X x) {return 0;} main() { 1 && f(3); // Calls X(3) and ~X() 0 && f(3); // bug: calls destructor only 1 || f(3); // bug: calls destructor only } --------------------------------------------------- Matt Mahoney, (407) 727-5431, mvm@epg.harris.com, mvm@trantor.harris-atd.com #include // in Zortech // in Turbo