1292 – Template argument deduction doesn't work

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1292 - Template argument deduction doesn't work
Summary: Template argument deduction doesn't work
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: Other Linux
: P2 normal
Assignee: Walter Bright
URL:
Keywords:
Depends on:
Blocks:
Reported: 2007年06月25日 08:24 UTC by Jari-Matti Mäkelä
Modified: 2014年02月16日 15:23 UTC (History)
0 users

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Jari-Matti Mäkelä 2007年06月25日 08:24:20 UTC
Code:
 class B {}
 class D : B {}
 template foo(S, T : S) { } // doesn't work
 // template foo(S, T : B) { } // this works for some reason
 alias foo!(B, D) bar;
Compiler output:
bug.d(7): template instance foo!(B,D) does not match any template declaration
----
I'm guessing here what should happen:
From http://www.digitalmars.com/d/template.html, Argument deduction:
The types of template parameters are deduced for a particular template
instantiation by comparing the template argument with the corresponding
template parameter.
For each template parameter, the following rules are applied in order
until a type is deduced for each parameter:
1. If there is no type specialization for the parameter, the type of
the parameter is set to the template argument.
 (S, T : S) -> (B, T : S)
2. If the type specialization is dependent on a type parameter, the
type of that parameter is set to be the corresponding part of the type
argument.
 (B, T : S) -> (B, T : B)
3. If after all the type arguments are examined there are any type
parameters left with no type assigned, they are assigned types
corresponding to the template argument in the same position in the
TemplateArgumentList.
 (B, T : B) -> (B, D)
4. If applying the above rules does not result in exactly one type for
each template parameter, then it is an error.
 ok?
Comment 1 Walter Bright 2007年07月01日 14:09:50 UTC
Fixed DMD 1.018 and DMD 2.002


AltStyle によって変換されたページ (->オリジナル) /