Bug 10843 – Combinatorial problem of struct & alias this & null

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-08-17T22:03:00Z
Last change time
2013-08-17T23:53:49Z
Assigned to
nobody
Creator
zan77137

Comments

Comment #0 by zan77137 — 2013-08-17T22:03:19Z
These tree samples don't work: ------------------ unittest { static struct HANDLE { void* h; alias h this; } //HANDLE a = null; // NG HANDLE a; a = null; // OK } unittest { static struct HANDLE { void* h; alias h this; this(void* h) { this.h = h; } } HANDLE a = null; // OK static void foo(HANDLE h){} //foo(null); // NG } unittest { static struct HANDLE { void* h; alias h this; this(void* h) { this.h = h; } } static struct WSAEVENT { HANDLE h; alias h this; this(HANDLE h) { this.h = h; } } auto a = cast(HANDLE)null; // OK //auto b = cast(WSAEVENT)null; // NG }
Comment #1 by maxim — 2013-08-17T23:53:49Z
This is invalid report in all there cases. 1) is implicit construction for which constructor with respective arguments should be defined (as provided in second example). 2) is implicit construction on argument passing for which variardic functions do exists. Spec is explicit that for such cases ctor is required. 3) same as #2 with difference that now function is a ctor This is compilable: unittest { static struct HANDLE { void* h; alias h this; } //HANDLE a = null; // NG HANDLE a; a = null; // OK } unittest { static struct HANDLE { void* h; alias h this; this(void* h) { this.h = h; } } HANDLE a = null; // OK static void foo(HANDLE h ...){} foo(null); // OK } unittest { static struct HANDLE { void* h; alias h this; this(void* h) { this.h = h; } } static struct WSAEVENT { HANDLE h; alias h this; this(HANDLE h ...) { this.h = h; } } auto a = cast(HANDLE)null; // OK auto b = cast(WSAEVENT)null; // OK } void main() {}