This shouldn't happen
Martin Nowak
dawg at dawgfoto.de
Thu Apr 26 17:56:20 PDT 2012
> We can't just use Typedef!(void*) or Typedef!(int) because -=/+= will
> be allowed, which shouldn't be allowed for handles. const(void*) won't
> work either, because you should be allowed to assign one handle to
> another and const forbids that.
struct None; // undefined struct as bottom type
alias None* HWND;
enum INVALID_HANDLE_VALUE = cast(HWND)-1;
static assert(__traits(compiles, {HWND h; h = INVALID_HANDLE_VALUE;}));
static assert(!__traits(compiles, {None n;}));
static assert(!__traits(compiles, {HWND h; ++h;}));
static assert(!__traits(compiles, {HWND h; h + 1;}));
HWND foo(HWND h)
{
return h;
}
void main()
{
HWND h;
assert(h is null);
h = foo(h);
assert(h is null);
h = foo(INVALID_HANDLE_VALUE);
assert(h is INVALID_HANDLE_VALUE);
h = foo(null);
assert(h is null);
}
More information about the Digitalmars-d
mailing list