On Saturday, 25 August 2018 at 22:53:44 UTC, Walter Bright wrote:
On 8/25/2018 2:46 PM, David Nadlinger wrote:
At least for the transition period, I'd have attributes only
apply to the user-specified code and infer them for the actual
full constructor. (We can still print a deprecation warning if
they don't match.) —David
Inferring is not good enough, for example:
https://github.com/dlang/dmd/pull/6816#issuecomment-307972790
There the @safe constructor is calling a destructor that calls
free(). It can't be inferred as @safe.
How did you interpret "only apply to the user-specified code"? In
this example, the `@safe` in `this() @safe {}` would only apply
to `{}`.
This necessitates being careful with the error message in a case
like this
struct UnsafeDtor { @system ~this() {} }
struct Foo {
UnsafeDtor ud;
this(int a) @safe {
if (!a) throw Exception("boo");
}
}
void bar() @safe {
auto f = Foo(1);
}
as just printing "cannot call @system constructor" would be a bit
misleading. It should work without surprises otherwise, though,
and can be supplemented with deprecation warnings if the
specified "inner" and inferred "outer" attributes don't match.
—David