Discussion Thread: DIP 1035-- at system Variables--Community Review Round 1
Timon Gehr
timon.gehr at gmx.ch
Wed Jun 10 14:22:25 UTC 2020
On 10.06.20 16:15, Stanislav Blinov wrote:
> From the feedback thread:
>
> On Wednesday, 10 June 2020 at 13:56:11 UTC, Timon Gehr wrote:
>> Memory safety cannot depend on the correctness of a `@safe` constructor.
>
>> struct VmInstruction {
>> @system Opcode opcode; // this need not be private, just a valid
>> enum member
>> this(Opcode opcode) @safe {
>> this.opcode = opcode; // forgot to check
>> }
>> }
>> ...
>> void main() @safe {
>> auto code = [VmInstruction(cast(Opcode)20)];
>> execute(code);
>> }
>
> Good observation. It *almost* feels like there's a case lurking for
> disallowing enum casts in @safe code.
enum Opcode{
decrement, increment, print,
}
...
void main() @safe {
auto code = [VmInstruction(Opcode.increment|Opcode.print)];
execute(code);
}
More information about the Digitalmars-d
mailing list