Re: compilation error in switch case in c++
On 6 Feb, 14:07, Pete Becker <p...@versatilecoding.com> wrote:
> On 2008-02-06 04:15:14 -0500, Rahul <sam_...@yahoo.co.in> said:
> > int main()
> > {
> > switch(1)
> > {
> > case 1 :
> > // {
> > A obj;
> > printf("case 1\n");
> > // }
> > break;
> > case 2 :
> > A obj1;
> > printf("case 2\n");
> > break;
> > }
> > }
>
> This is illegal. When should obj's destructor be run?
>
I fail to see how this is illegal, even if the brackets are not there:
A program that jumps from a point where a local variable with
automatic storage duration is not in scope to a point where it is in
scope is ill-formed __unless__ the variable has POD-type and is
declared without an initializer. (6.7/3, emphasis mine)
> > jump to case symbol
> > enters scope of non-POD 'A obj'
If A turned out to be non-POD it would be illegal and the compiler
error would be correct.
|