[Issue 4446] New: Templated function result can't be ref if tiargs are infered w/ value tiarg
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jul 11 03:02:47 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4446
Summary: Templated function result can't be ref if tiargs are
infered w/ value tiarg
Product: D
Version: 2.041
Platform: All
OS/Version: All
Status: NEW
Keywords: rejects-valid
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: rsinfu at gmail.com
--- Comment #0 from Shin Fujishiro <rsinfu at gmail.com> 2010-07-11 03:02:42 PDT ---
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;
}
--------------------
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list