Bug 4446 – Templated function result can't be ref if tiargs are infered w/ value tiarg

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-07-11T03:02:00Z
Last change time
2014-02-15T02:43:28Z
Keywords
rejects-valid
Assigned to
nobody
Creator
rsinfu

Comments

Comment #0 by rsinfu — 2010-07-11T03:02:42Z
Templated function (free nor member) cannot return by-ref explicitly (i.e. not with auto ref) if instantiation arguments are infered and the instantiation arguments contain at least one value argument. This does not compile: -------------------- void main() { S s; s.opDispatch!"bar"(42); // fails } struct S { ref int opDispatch(string str, T)(T arg) { return _xyz; } int _xyz; } -------------------- % dmd -o- -c test test.d(8): Error: variable test.S.str only parameters or foreach declarations can be ref -------------------- The error does not occur if the template instantiation arguments are not infered: -------------------- void main() { S s; s.opDispatch!("bar", int)(42); // fine } ... -------------------- Auto ref is fine: -------------------- void main() { S s; s.opDispatch!"bar"(42); // fine } struct S { auto ref opDispatch(string str, T)(T arg) { return _xyz; } int _xyz; } -------------------- This is a workaround for opDispatch: -------------------- struct S { template opDispatch(string str) { ref int opDispatch(T)(T arg) { return _xyz; } } int _xyz; } --------------------
Comment #1 by rsinfu — 2010-09-20T22:03:05Z
*** This issue has been marked as a duplicate of issue 3175 ***