On Fri, Feb 14, 2003 at 12:50:43PM -0500, Daniel Jacobowitz wrote:
> On Fri, Feb 14, 2003 at 12:14:01AM -0500, H. S. Teoh wrote:
[snip]
> > Also, why doesn't g++ like the declaration of objects inside a switch
> > statement? Is this invalid according to the C++ spec, or is it a GCC
> > oddity? Regardless, the internal compiler error is certainly a bug. 
> 
> I'm pretty sure it's illegal.  Consider this - what is the scope of
> obj1 in the below?  It starts at the first label, and goes until the
> end of the case block.  So it's in scope at CHOICE_B.  But its
> constructor wasn't called....
[snip]

Ah, I see. I guess I'm so used to writing cases with break's that I forgot
that C/C++ semantics allow cases to fall through to the next case. I had
intended the semantics to be:

        switch (choice) {
          case A: {
            someobj x;
            ...
          }
          break;
          case B: {
            ...
          }
          break;
          ...
        }

Obviously, this isn't the case with what I actually wrote.


T

-- 
GEEK = Gatherer of Extremely Enlightening Knowledge


Reply via email to