Bug 12734 – Template cannot deduce E[] from typeof(null)
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-05-11T20:08:07Z
Last change time
2018-04-17T16:28:21Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Andrej Mitrovic
Comments
Comment #0 by andrej.mitrovich — 2014-05-11T20:08:07Z
-----
void take1(int[] buffer) { }
void take2(E)(E[] buffer) { }
void main()
{
take1(null); // ok
take2(null); // fail
}
-----
I'm not sure what 'E' would be deduced to with a typeof(null) though. Maybe just a 'void'? Or a 'void*'? It's hard to tell, but the above forces us to create overloads for the sake of supporting null.
Comment #1 by yebblies — 2014-05-13T13:22:03Z
I'm not so sure this is a good idea, but I guess there's precedent.
Comment #2 by ag0aep6g — 2018-04-17T16:28:21Z
(In reply to Andrej Mitrovic from comment #0)
> -----
> void take1(int[] buffer) { }
> void take2(E)(E[] buffer) { }
>
> void main()
> {
> take1(null); // ok
> take2(null); // fail
> }
> -----
>
> I'm not sure what 'E' would be deduced to with a typeof(null) though. Maybe
> just a 'void'? Or a 'void*'? It's hard to tell, but the above forces us to
> create overloads for the sake of supporting null.
Works since 2.067.1, with E = void. Closing as worksforme. https://run.dlang.io/is/QhvCjh