D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4843 - Inconsistency in overloading ref vs. non-ref
Summary: Inconsistency in overloading ref vs. non-ref
Status: RESOLVED DUPLICATE of issue 5889
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
: 6201 7409 (view as issue list)
Depends on: 5889
Blocks:
  Show dependency treegraph
 
Reported: 2010-09-09 06:03 UTC by David Simcha
Modified: 2012-04-22 16:38 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description David Simcha 2010-09-09 06:03:33 UTC
The following code compiles and correctly resolves the lvalue vs. non-lvalue overloading:

import std.stdio;

void doStuff(const ref int i) {
    writeln("Doing stuff by ref.");
}

void doStuff(const int i) {
    writeln("Forwarding to ref overload.");
    doStuff(i);
}

void main() {
    doStuff(1);
} 

Similar code also works for classes and arrays.  It seems to be broken for structs, though.  The following code is rejected:

import std.stdio;

struct S {}

bool fun(const ref S rhs) {
    return true;
}

bool fun(const S rhs) {
    return fun(rhs);
}

test9.d(12): Error: function test9.fun called with argument types:
	((const(S)))
matches both:
	test9.fun(ref const const(S) rhs)
and:
	test9.fun(const const(S) rhs)
Comment 1 Kenji Hara 2011-06-24 04:48:56 UTC
*** Issue 6201 has been marked as a duplicate of this issue. ***
Comment 2 Kenji Hara 2011-06-24 04:54:00 UTC
This issue is part of bug5889. Add 'Depends on'.
Comment 3 yebblies 2012-01-31 07:46:56 UTC
*** Issue 7409 has been marked as a duplicate of this issue. ***
Comment 4 SomeDude 2012-04-20 09:10:43 UTC
Compiles on 2.059 Win32
Comment 5 jens.k.mueller 2012-04-22 13:30:29 UTC
Indeed. The issue seems to be fixed.
Comment 6 Kenji Hara 2012-04-22 16:38:58 UTC

*** This issue has been marked as a duplicate of issue 5889 ***