xxxxxxxxxx
struct ClassContext
{
static:
class Base { }
class Derived : Base { }
void f(Base*) { }
void g(const(Base)*) { }
void test()
{
Base base = new Derived;
Derived derived = new Derived;
f(&base);
static assert(!__traits(compiles,
f(&derived)
));
g(&base);
g(&derived);
}
}
struct DelegateContext
{
static:
alias SysDG = void delegate();
alias SafeDG = void delegate() ;
void f(SysDG*) { }
void g(const(SysDG)*) { }
void test()
{
SysDG sysDG = { };
SafeDG safeDG = { };
f(&sysDG);
static assert(!__traits(compiles,
f(&safeDG)
));
g(&sysDG);
g(&safeDG);
}
}
struct FunctionPtrContext
{
static:
alias SysFP = void function();
alias SafeFP = void function() ;
void f(SysFP*) { }
void g(const(SysFP)*) { }
void test()
{
SysFP sysFp = { };
SafeFP safeFp = { };
f(&sysFp);
static assert(!__traits(compiles,
f(&safeFp)
));
g(&sysFp);
g(&safeFp);
}
}