10 ms·
Why remove RAII? It's not fundamentally incompatible with "Better C" semantics, especially if there are no exceptions.
by Ace17 9y ago
Why remove RAII?
It's not fundamentally incompatible with "Better C" semantics, especially if there are no exceptions.
- zombinedev 9y agoRAII in not removed by design. It is just work in progress. It will be added to -betterC when its implementation is more mature for this mode.
- WalterBright 9y agoRAII requires exceptions to be correct. I hesitate to say it it has RAII otherwise. Exceptions have two issues: 1. D exceptions currently require the GC. There is a Pull Request to fix that, but it isn't incorporated yet. 2. More problematic is the Dwarf exception handling mechanism requires a language specific "personality" handler. This is supplied by the D runtime library. Trying to trick the C runtime library one into working with D isn't a solved problem at the moment.
- andrewflnr 9y ago> RAII requires exceptions to be correct. I'm not exactly sure what you mean here, but all I really want is guaranteed destructors. Can we just have those?
- WalterBright 9y ago> Can we just have those? It's a good thought. D as Better C is new for us, and we'll be flexible in making it work better.
- millstone 9y agoWhy does RAII require exceptions? RAII is routinely used in C++ with -fno-exceptions.
- WalterBright 9y agoBecause D code may sit in between code that throws and exception and code that handles it. Without EH support, the RAII destructor won't get called when the stack is unwound.
- millstone 9y agoGotcha. C++ has the same problem when its exceptions are thrown through C or -fno-exceptions C++ frames. If that's the only hold-up, IMO the way to go is to abort at the boundary, when an exception would propagate into frames without unwind tables. RAII is too valuable to do without!
- dbaupp 9y agoIsn't it generally undefined behaviour to have exceptions pass through code that isn't compiled with support for them? I.e. not running some destructors is the least of your worries if an exception hits C/-fno-exceptions/-betterC code.
- WalterBright 9y agoUndefined behavior or not, implementations of languages in gcc and Windows tend to support it, even if the language itself does not. I consider it my job to make this work if at all practical, because users do not like ugly surprises. I don't know how Rust's RAII deals with exceptions thrown by lower level code. If someone better acquainted with Rust could chime in here, it would be interesting.
- vvanders 9y agoRust uses RAII all over the place and doesn't have exceptions :).