The D standard library is built on GC, is that a negative or positive?

bauss jacobbauss at gmail.com
Fri Dec 16 13:56:19 UTC 2022


On Friday, 16 December 2022 at 13:25:25 UTC, Nick Treleaven wrote:
> On Friday, 16 December 2022 at 04:54:21 UTC, Siarhei Siamashka 
> wrote:
>> Another problem is illustrated by the example below:
>>
>> ```D
>> T enforce(string msg, T)(T cond) {
>>     if (!cond) {
>>         static immutable e = new Exception(msg);
>>         throw e;
>>     }
>>     return cond;
>> }
>>
>> void main() {
>>     try {
>>         enforce!"trigger an exception"(1 == 2);
>>     } catch (Exception e) {
>>         assert(0, "if we reach here, then it's probably a 
>> compiler bug");
>>     } catch (immutable Exception e) {
>>         // the proper place to handle it is here
>>         assert(e.msg == "trigger an exception");
>>     }
>> }
>> ```
>>
>> If it's an immutable exception, then the compiler should 
>> probably only catch it as immutable?
>
> This pull disallows throwing an immutable object:
>
> https://github.com/dlang/dmd/pull/14706
>
> You can still throw a const object though, which would work for 
> your `enforce`.

Personally I think it should always just be implied const like:

catch (Exception e) should imply catch (const e) that way both 
mutable and immutable will work.


More information about the Digitalmars-d mailing list