No we should not support enum types derived from strings
deadalnix
deadalnix at gmail.com
Wed May 12 12:11:22 UTC 2021
On Wednesday, 12 May 2021 at 11:41:20 UTC, Andrei Alexandrescu
wrote:
> On 5/11/21 9:46 PM, deadalnix wrote:
>> This whole model in C++ is unsound. It's easy to show. In you
>> above example, the this pointer, typed as Widget*, points to
>> an instance of a subclass of Widget. If you were to assign a
>> Widget to that pointer (which you can do, this is a pointer to
>> a mutable widget), then any references to that widget using a
>> subtype of Widget is now invalid.
>
> All of this is bizarrely incorrect. Care to elaborate?
Consider the following: https://godbolt.org/z/8vzx9W56a
This is a clear demonstration that C++'s type system is unsound
here.
It is unsound because it has the property that you mentioned in
your post: the pointer is monomorphic and the value this pointers
points to is polymorphic. This is simply unsound, you cannot
separate the two (unless you make everything immutable).
The pointer and the value must come together as a bundle, and
that whole bundle (which is a value type containing a reference)
is itself what is polymorphic. That's what Java/C#/D do and this
is right.
More information about the Digitalmars-d
mailing list