@disable("reason")

Jonathan M Davis newsgroup.d at jmdavisprog.com
Wed Jan 8 13:06:33 UTC 2020


On Wednesday, January 8, 2020 4:54:06 AM MST Simen Kjærås via Digitalmars-d-
learn wrote:
> On Wednesday, 8 January 2020 at 07:03:26 UTC, Jonathan M Davis
>
> wrote:
> > you could just document that no one should ever use its init
> > value explicitly, and that they will have bugs if they do
>
> You also create a static init member marked @disable:
>
> struct S {
>      @disable this();
>      @disable static S init();
> }
>
> This will give sensible error messages anywhere .init is being
> used. Now, Phobos and other libraries might expect that .init is
> always working, so this could potentially be a problem.

That's likely to break a _lot_ of generic code, because init is used heavily
in template constraints and static if conditions as the way to get a value
of that type to test. It's also actually been argued before that it should
be illegal to declare a symbol called init on any type, which is one reason
why the init member was removed from TypeInfo. I'd strongly advise against
anyone declaring a struct or class member named init whether it's @disabled
or not.

- Jonathan M Davis






More information about the Digitalmars-d-learn mailing list