No we should not support enum types derived from strings

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Wed May 12 14:52:42 UTC 2021


On Tuesday, 11 May 2021 at 21:36:46 UTC, Andrei Alexandrescu 
wrote:
> Values are monomorphic. Years ago I found a bug in a large C++ 
> system that went like this:
>
> class Widget : BaseWidget {
>     ...
>     Widget* clone() {
>         assert(typeid(this) == typeid(Widget*));
>         return new Widget(*this);
>     }
> };
>
> The assert was a _monomorphism test_, i.e. it made sure that 
> the current object is actually a Widget and not something 
> derived from it, who forgot to override clone() once again.

I don't understand what you mean by pointers being monomorphic.

this will always have the type of the class it was defined in. So 
the assert will always hold.

How is this surprising???

What is more dangerous is that if you forget to add a virtual 
member then *this will also always hold as being a Widget.

That is the result of C++ being a low-level language. No sensible 
high level language would allow such semantics.





More information about the Digitalmars-d mailing list