Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!ai.mit.edu!tiemann From: tiemann@ai.mit.edu (Micheal Tiemann) Newsgroups: gnu.g++.bug Subject: hard bug Message-ID: <9001111953.AA13433@apple-gunkies.ai.mit.edu> Date: 11 Jan 90 19:53:07 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 37 Here's a C++ teaser. What's wrong with the following code? extern "C" void printf (char *, ...); struct X { int x; X (int i) { x = i; } ~X () { printf ("destroying object %d\n", x); } }; main () { int i = foo (); if (i) for (X x(5); i < 10; i++) { printf ("loop count = %d\n", i); } Greyhawk: ; } int foo () { return 0; } More precisely, when execution reaches Greyhawk, 1. Is `x' in scope? 2. If so, it is initialized? 3. Where and when is `x' destroyed? If the scope of `x' were limited to the scope of the for loop, none of these problems would be "interesting", and everything work work as one might expect. Michael