You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
voidmain()
{
int x;
reftypeof(x) r0 = x; // goodauto reftypeof(x) r1 = 0; // goodtypeof(function{ return0; }()) v0 = x; // goodtypeof(function{ return0; }()) v1 = 0; // goodreftypeof(function{ return0; }()) r2 = x;
// Error: cannot `ref` return constant `0`// Error: type `int` cannot be assigned to `ref _error_ r2`auto reftypeof(function{ return0; }()) r3 = x;
// Error: cannot `ref` return constant `0`auto reftypeof(function{ return0; }()) r4 = 0;
// Error: cannot `ref` return constant `0`typeof(functionref{ return x; }) fp0; // infers `ref int function() pure nothrow @nogc @safe` (`ref` needed)/*auto*/reftypeof(function{ return x; }) fp = fp0; // Note: no `ref` after `function`staticassert(__traits(isRef, fp)); // `fp` is a reference variable: as intendedstaticassert(is(typeof(&fp()))); // `fp` returns by reference: makes no sense// With`auto ref` instead of `ref`: No change in behavior
}
It seems the presence of ref or auto ref on the variable makes the function literal within typeof have a ref return. If within the literal, return 0; is replaced by returning a local variable,
The text was updated successfully, but these errors were encountered:
It seems the presence of
ref
orauto ref
on the variable makes the function literal withintypeof
have aref
return. If within the literal,return 0;
is replaced by returning a local variable,The text was updated successfully, but these errors were encountered: