#dbugfix 18493
Mike Franklin
slavo5150 at yahoo.com
Tue Apr 17 14:40:12 UTC 2018
On Tuesday, 17 April 2018 at 12:13:06 UTC, Mike Franklin wrote:
> On Tuesday, 17 April 2018 at 05:33:53 UTC, Radu wrote:
>
>> This is very odd, as the following compiles:
>> ---
>> struct S
>> {
>> this(this)
>> {
>> }
>>
>> ~this()
>> {
>> }
>> }
>>
>> struct C
>> {
>> S s1;
>> }
>> ---
>>
>> If the scope failure would cause this then I assume it would
>> not work at all in any case.
>
> Yeah! I think that is also a bug.
Nope, that's not a bug. The reason the try-catch is only
generated with two or more fields is to ensure that if an
exception is thrown while blitting `s2`, `s1`'s destructor will
still be called.
I'm not sure what the proper fix is yet. The compiler could
require you to attribute `this(this)` with `nothrow` in order to
promise the compiler that it won't throw. Then the compiler
would know that it wouldn't need to add the try-catch around the
postblit because there's no way for it to throw. That would also
ensure consistent behavior when compiling the same code with or
without -betterC.
However, since throwing is off-limits entirely for -betterC, it
doesn't make much sense to generate try-catch statements, only to
have the compiler emit an error about it.
Maybe I should implement both. I need to sleep on it.
Mike
More information about the Digitalmars-d
mailing list