Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Ticket #118 (new defect)

Opened 2 months ago

Last modified 2 months ago

"cannot put catch statement inside finally block"

Reported by: fvbommel Assigned to:
Priority: major Milestone:
Component: Version:
Keywords: Cc:

Description

I get an error ("cannot put catch statement inside finally block") on the following code:

module test;

extern(C) int printf(char*, ...);

void verify() {}

void main() {
    scope(success) {
        scope(failure)
            printf("Verification failed!\n");
        verify();
    }

}

DMD gives the same error, but GDC allows this without complaining. Since GDC and LLVM both use DWARF exception handling (right?), this should work in LDC as well, shouldn't it?

Unfortunately, it's not as simple as disabling the error: changing dmd/statement.c:3549 to "#if !defined(IN_GCC) && !defined(IN_LLVM)" produces the following error on compiling the testcase:

ldc: <>/ir/irlandingpad.cpp:25: IRLandingPadInfo::IRLandingPadInfo(Catch*, llvm::BasicBlock*):
Assertion `!catchstmt->var->ir.irLocal' failed.

Change History

11/16/08 02:11:50 changed by ChristianK

Yes, it should indeed be possible. The assert you're getting is about the storage for the catch variable and can probably be avoided easily (sounds like a frontend issue, at first glance).

However, the D spec says "A FinallyStatement? may not contain any Catches. This restriction may be relaxed in future versions.", so this seems to be one of the backward compatible but not forward compatible changes that break with the D spec.

11/16/08 06:04:34 changed by fvbommel

Did you look at my testcase? There is no FinallyStatement. There's just nested scope statements. Even if scope(*) is emulated with catch & finally, the scope(success) one shouldn't be "finally" because it doesn't need to run on exceptions (so it could just be inserted before every return), and the scope(failure) should be a "catch" & rethrow, not a "finally".

Besides, even if there was a scope(exit) in there, which would be equivalent to a finally clause, the spec makes no mention of the same restriction applying to ScopeGuardStatements.

Copyright © 2008, LDC Development Team.