Thread overview
auto classes
Jun 15, 2004
Sark7
Jun 16, 2004
Arcane Jill
June 15, 2004
At now auto classes must be declared explicitly to get RAII to work.
But implicit declaration can be very useful, like following:

[code]
auto class A
{
  ~this()
  {
    printf("A dtor"\n);
  }
}

void foo(A a) {}

void bar()
{
  foo(new A());
  printf("A out of the scope"\n);
}

void main()
{
  bar();
}
[/code]

Currently I must to declare `auto A a = new A()` in bar() and pass `a` to foo(), but it is not good enough for me :)

Besides, default behaviuor seems like a bug, because `new A()` passed to foo() in that case is not auto reference; and collected as non-auto class.
June 16, 2004
In article <opr9nrzfikut8jae@zaitseff.tec.amursk.ru>, Sark7 says...
>
>Besides, default behaviuor seems like a bug, because `new A()` passed to foo() in that case is not auto reference; and collected as non-auto class.

Yeah, that sounds like a bug to me. With a slight modification to the code, this bug becomes stunningly obvious:

>auto class A
>{
>   ~this()
>   {
>     printf("A dtor"\n);
>   }
>}
>
>void foo(A a) {}
>
>void bar()
>{
>   foo(new A());
>   printf("A out of the scope"\n);
>}
>
>void main()
>{
>   bar();
>   printf("For correct RAII, A should have been deleted BEFORE this point\n");
>}

Prints:

>A out of the scope
>For correct RAII, A should have been deleted BEFORE this point
>A dtor

Arcane Jill



June 16, 2004
Arcane Jill wrote:
> In article <opr9nrzfikut8jae@zaitseff.tec.amursk.ru>, Sark7 says...
> 
>>Besides, default behaviuor seems like a bug, because `new A()` passed to  foo() in that case is not auto reference; and collected as non-auto class.
> 
> 
> Yeah, that sounds like a bug to me. With a slight modification to the code, this
> bug becomes stunningly obvious:
> 
> 
>>auto class A
>>{
>>  ~this()
>>  {
>>    printf("A dtor"\n);
>>  }
>>}
>>
>>void foo(A a) {}
>>
>>void bar()
>>{
>>  foo(new A());
>>  printf("A out of the scope"\n);
>>}
>>
>>void main()
>>{
>>  bar();
>>  printf("For correct RAII, A should have been deleted BEFORE this point\n");
>>}
> 
> 
> Prints:
> 
> 
>>A out of the scope
>>For correct RAII, A should have been deleted BEFORE this point
>>A dtor
> 
> 
> Arcane Jill

" When an auto class reference goes out of scope, the destructor (if any) for it is automatically called. This holds true even if the scope was exited via a thrown exception."

This really is a showstopping bug, as often you absolutely *must* be sure that some resource is released before running subsequent code.

*nudges Walter*

Cheers,
Sigbjørn Lund Olsen