540 – Nested template member function error - "function expected before ()"

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 540 - Nested template member function error - "function expected before ()"
Summary: Nested template member function error - "function expected before ()"
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: All All
: P2 blocker
Assignee: Walter Bright
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
Reported: 2006年11月17日 07:37 UTC by Bill Baxter
Modified: 2014年02月15日 13:20 UTC (History)
2 users (show)

See Also:


Attachments
patch to DMD 0.175 (870 bytes, patch)
2007年06月21日 06:02 UTC, Oskar Linde
Details | Diff
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 Bill Baxter 2006年11月17日 07:37:25 UTC
A template member function with nesting confuses the compiler. It is fine with the equivalent construct existing outside a class. It only breaks when you put it inside the class.
class Foo {
 template myCast(T) {
 T myCast(U)(U val) {
 return cast(T) val;
 }
 }
}
void main() {
 Foo foo = new Foo;
 int i = foo.myCast!(int)(1.0);
} 
-->
Error: function expected before (), not 'foo dotexp template myCast(U)'
Comment 1 Christian Kamm 2007年04月24日 03:18:20 UTC
You can also easily trigger this IFTI problem with named template mixins:
template A()
{
 static void foo(T)(T t) {}
}
struct Bar
{
 mixin A!() a;
}
void main()
{
 A!().foo(1); // works
 Bar.a.foo!(int)(1); // works
 Bar.a.foo(1); // error
}
Error: function expected before (), not 'Bar dotexp template foo(T)'
Comment 2 clayasaurus 2007年06月20日 10:38:53 UTC
This issue is a show stopper for the Arc v.2 release, unless we find a workaround of some sort. 
Comment 3 Oskar Linde 2007年06月21日 06:02:09 UTC
Created attachment 148 [details] 
patch to DMD 0.175
Comment 4 Oskar Linde 2007年06月21日 06:03:05 UTC
Here is a patch to DMD 0.175 that fixes this issue (posted december 1st to the announce newsgroup). It is not really well tested, but illustrates that the required change is quite small.
Comment 5 Walter Bright 2007年07月01日 13:25:47 UTC
Fixed DMD 1.018 and DMD 2.002


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