Bug 9840 – Methods in templates should likely not require the 'this' reference

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-30T13:10:00Z
Last change time
2013-11-24T04:10:25Z
Keywords
rejects-valid
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2013-03-30T13:10:03Z
struct S { template T() { bool get() { return true; } enum bool T = get(); } } void main() { S s; S.T!(); // NG s.T!(); // NG } The 'get' function cannot be called even if we have a this reference. But I don't think the above should require a this reference. It's an inner method that doesn't touch any fields of struct S. The workaround is to mark the inner function as static.
Comment #1 by yebblies — 2013-11-22T07:59:46Z
Do you really want it to automatically make inner methods static? That seems like a bit much.
Comment #2 by andrej.mitrovich — 2013-11-23T08:49:15Z
(In reply to comment #1) > Do you really want it to automatically make inner methods static? That seems > like a bit much. No. I always forget that templated functions are really: template foo(T) { void foo(T t) { } } So that was my mistake. But I think the call through the instance should work, no?
Comment #3 by yebblies — 2013-11-23T19:23:18Z
(In reply to comment #2) > (In reply to comment #1) > > Do you really want it to automatically make inner methods static? That seems > > like a bit much. > > No. I always forget that templated functions are really: > > template foo(T) > { > void foo(T t) { } > } > > So that was my mistake. But I think the call through the instance should work, > no? But you never call it through an instance. 'get' only gets called from the enum's initializer, which does _not_ have an instance.
Comment #4 by andrej.mitrovich — 2013-11-24T04:10:25Z
(In reply to comment #3) > But you never call it through an instance. 'get' only gets called from the > enum's initializer, which does _not_ have an instance. Ah, good point. This issue is invalid.