[Issue 1528] [tdpl] overloading template and non-template functions
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Feb 28 20:47:11 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=1528
--- Comment #16 from Kenji Hara <k.hara.pg at gmail.com> 2013-02-28 20:46:30 PST ---
(In reply to comment #13)
> // vs specialized parameter
> int f4(int a) { return 1; }
> int f4(T:int)(T b) { return 2; }
> static assert(f4(1)==1);
Just only this is wrong. f4(T:int) is specialized to int argument, so f4(1)
could match both normal function version and template version *with the same
extent*. Then it will be ambiguous.
> static assert(f4(1L)==1);
Ok. f4(T:int) cannot instantiate with T==long, so first version will be called.
(In reply to comment #15)
> (In reply to comment #14)
> > ...
> >
> > static assert(f6(1L) == 1);
> > static assert(f6(ulong.max) == 2); // (a) ???
> >
>
> No match.
>
> > ulong ul = runtime();
> > static assert(f6(ul) == 2); // (b) ???
> >
>
> No match.
Both (a) and (b) should be "no match", but with my experimental change, (a)
wrongly matches to int. I found an another bug in there, and filed it as bug
9617.
Current test case results with my pull request:
https://github.com/D-Programming-Language/dmd/pull/1409
is:
--------
int f1(int a, double=10) { return 1; }
int f1(int a, string="") { return 2; }
int f2(T:int)(T b, double=10) { return 1; }
int f2(T:int)(T b, string="") { return 2; }
// vs deduced parameter
int f3(int a) { return 1; }
int f3(T)(T b) { return 2; }
// vs specialized parameter
int f4(int a) { return 1; }
int f4(T:int)(T b) { return 2; }
// vs deduced parameter + template constraint (1)
int f5(int a) { return 1; }
int f5(T)(T b) if (is(T == int)) { return 2; }
// vs deduced parameter + template constraint (2)
int f6(int a) { return 1; }
int f6(T)(T b) if (is(T : int)) { return 2; }
// vs nallowing conversion
int f7(ubyte a) { return 1; }
int f7(T)(T b) if (is(T : int)) { return 2; }
void main()
{
static assert(!__traits(compiles, f1(1))); // ambiguous
static assert(!__traits(compiles, f1(1L))); // ambiguous
static assert(!__traits(compiles, f2(1))); // ambiguous
static assert(!__traits(compiles, f2(1L))); // no match
assert(f3(1) == 1);
assert(f3(1L) == 2);
static assert(!__traits(compiles, f4(1)));
assert(f4(1L) == 1);
assert(f5(1) == 1);
assert(f5(1L) == 1);
assert(f6(1) == 1);
assert(f6(1L) == 1);
static assert(!__traits(compiles, f6(ulong.max))); // no match
// needs to fix bug 9617
ulong ulval = 1;
static assert(!__traits(compiles, f6(ulval))); // no match
assert(f7(200u) == 2);
assert(f7(400u) == 2);
uint uival = 400; // TDPL-like range knowledge lost here.
assert(f7(uival) == 2);
a = 200; // Ditto.
assert(f7(uival) == 2);
}
--------
I welcome more complicated test case.
--
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