2499 – Template alias default value cannot be template instantiation

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2499 - Template alias default value cannot be template instantiation
Summary: Template alias default value cannot be template instantiation
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: Walter Bright
URL:
Keywords: rejects-valid
Depends on:
Blocks:
Reported: 2008年12月08日 15:44 UTC by Steven Schveighoffer
Modified: 2015年06月09日 01:20 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 Steven Schveighoffer 2008年12月08日 15:44:00 UTC
Simple case:
void foo(T)()
{
}
struct f(alias func=foo!(int))
{
}
void main()
{
 f!() myf;
}
Error in 1.036:
Error: foo!(int) is not a symbol
Error in 2.019:
testtemplatealias.d(5): Error: foo!(int) is used as a type
testtemplatealias.d(11): template instance f!() does not match template declaration f(alias func = foo!(int))
testtemplatealias.d(11): Error: f!() is used as a type
testtemplatealias.d(11): variable testtemplatealias.main.myf voids have no value
Workaround is to alias the default parameter before using as the default parameter:
alias foo!(int) defaultFoo;
struct f(alias func=defaultFoo)
{
}
Comment 1 Steven Schveighoffer 2008年12月08日 15:47:45 UTC
Note that in the case where you want the default value to depend on other template parameters, such as:
struct f(T, alias func=foo!(T))
This is much tricker. I found that the cleanest way to workaround is to avoid default parameters, and just alias the less specific ones:
struct f(T, alias func)
{
}
template f(T)
{
 alias f!(T, foo!(T)) f;
}
Comment 2 Walter Bright 2008年12月25日 04:39:37 UTC
Fixed dmd 1.038 amd 2.022


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