[Issue 5896] const overload matching is succumb to template parameter one

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Apr 29 16:56:49 PDT 2011


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



--- Comment #2 from Kenji Hara <k.hara.pg at gmail.com> 2011-04-29 16:53:00 PDT ---
(In reply to comment #1)
> I don't understand why case 2a,2b works.
> It seems to me that case 1 is identical to:
> 
> struct X{}
> 
> T  foo(T)(const(X) _this) { return 10; }
> 
> T  foo(T)(X _this) { return 11; }
> 
> void main(){
>     auto xm = X();
>     assert(foo!int(xm)==11);
> }
> 
> Which fails in exactly the same way.

I have just started reading the code around the template, template function
matching may have three steps:

1. Tempate parameter vs explicit template arguments.
   ex. opCast(T)() vs opCast!X() -> T vs X
2. const overload matching on ethis
   void f(T)() vs const void f(T)() -> (mutable) vs const
3. function parameters type matching (and may inference of implict template
parameters)
   void f(X x) vs void f(const(X) x) -> X vs const(X)

The cause of this issue may be step 1 and 2, and cause of your test case may be
3.

----
Re-explain of my test case. on xm (type is X) lookup...
1a matching:
  step1: opCast(T) vs opCast!(int) -> MATCHconvert
  step2: through                   -> MATCHconst
  -> afterward result: MATCHconvert
1b matching:
  step1: opCast(T) vs opCast!(int) -> MATCHconvert
  step2: MATCHconst if can         -> !!! MATCHconst is succomb to MATCHconvert
  -> afterward result: MATCHconvert
Both result of 1a and 1b are MATCHconvert, so make ambiguous.

2a matching:
  step1: opCast(T:int) vs opCast!(int) -> MATCHexact
  step2: through
  -> afterward result: MATCHexact
2b matching:
  step1: opCast(T:int) vs opCast!(int) -> MATCHexact
  step2: MATCHconst if can             -> MATCHconst
  -> afterward result: MATCHconvert
2a is more specialized than 2b, then 2a is selected.

-- 
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