[Issue 9410] Wrong selection for function overload

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jan 28 02:40:45 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9410



--- Comment #3 from rswhite4 at googlemail.com 2013-01-28 02:40:36 PST ---
(In reply to comment #1)
> Reduced (Error: S() is not an lvalue)
> 
> import std.stdio;
> 
> struct S {}
> 
> void foo(float f, ref const S s)
> {
>     writeln("const");
> }
> 
> void foo(float f, const S s)
> {
>     writeln("ref const");
> }
> 
> void main()
> {
>     foo(1, S()); // 1f fixes code and calls ref const version
> }
> 
> 
> If overloaded functions have several parameters, one of which is
> const-qualified used-defined type and functions differer only in refness of
> that parameter, supplying implicitly convertible arguments (like int to float)
> to other parameters breaks compiler. 
> 
> Passing 1f results in calling ref const version which contradicts to recent
> revertion of passing struct literals by ref (however that was without const).
> It is unclear what should happen in presence of const.

The problem isn't the presence of const.
This code fails, also:

[code]
import std.stdio;

struct S {}

void foo(float f, ref S s)
{
   writeln("ref");
}

void foo(float f, S s)
{
   writeln("without ref");
}

void main()
{
    S s;
       foo(1, s); // works fine. Print: ref
    //foo(1, S()); // Fails with: Error: S() is not an lvalue
}
[/code]

IMO the problem is, that the compiler cannot convert 1 (int) to 1f (float).
He found the correct match: foo(float f, S s).
But the compiler could not convert int to float, so he tried another "match",
which is wrong because S() is not an lvalue.
That recognize the compiler and print an error. But IMO he should convert int
to float by his first match, which was the only correct match.
I believe the problem comes from the change that structs aren't handled as
lvalues anymore. Something of the old behaviour interfere with the new
behaviour.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list