[Issue 11857] `out` parameter breaks overload resolution
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Jan 13 01:09:11 PST 2014
https://d.puremagic.com/issues/show_bug.cgi?id=11857
--- Comment #4 from Kenji Hara <k.hara.pg at gmail.com> 2014-01-13 01:09:04 PST ---
(In reply to comment #3)
> So do I understand correctly ICE part of the issue is considered a duplicate of
> issue 11822 and "This code should compile" part is considered WONTFIX? If so,
> where is the documentation claiming such code incorrect?
In short, yes.
Even `const int n = 1` is interpreted in compile time, `n` is a local variable
that has runtime storage on stack. Therefore, expression `n` makes lvalue, then
preferentially matches to `out` parameter.
This behavior is intended to reduce confusion at the situation that mixing
constant-folding and compile-time/runtime evaluation. Example:
void f( immutable int n);
void f(ref immutable int n); // accepts only lvalue
void foo(int x)
{
immutable int n = x;
// n is evaluated in runtime (when foo is called)
f(n); // n matches to ref version
}
void bar(int x)
{
immutable int n = 1;
// n can be interpreted at compile time,
// but still allocated on stack and initialized in runtime.
f(n); // n still matches to ref version
}
D is designed to provide consistent overload resolution result for f(n) in both
foo and bar.
In other words, variable evaluation and its ref-ness is strictly separated from
the CTFE/constant-folding. Conflating them would make hard to understand
overload resolution result.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list