mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-11-30 20:54:19 +01:00
Support structs that are merely a forward reference. See mini/forwdecl1.d
This commit is contained in:
+9
-3
@@ -131,11 +131,17 @@ void DtoResolveStruct(StructDeclaration* sd)
|
|||||||
Logger::println("DtoResolveStruct(%s): %s", sd->toChars(), sd->loc.toChars());
|
Logger::println("DtoResolveStruct(%s): %s", sd->toChars(), sd->loc.toChars());
|
||||||
LOG_SCOPE;
|
LOG_SCOPE;
|
||||||
|
|
||||||
if (sd->prot() == PROTprivate && sd->getModule() != gIR->dmodule)
|
|
||||||
Logger::println("using a private struct from outside its module");
|
|
||||||
|
|
||||||
TypeStruct* ts = (TypeStruct*)sd->type->toBasetype();
|
TypeStruct* ts = (TypeStruct*)sd->type->toBasetype();
|
||||||
|
|
||||||
|
// this struct is a forward declaration
|
||||||
|
// didn't even know had those ...
|
||||||
|
if (sd->sizeok != 1)
|
||||||
|
{
|
||||||
|
sd->ir.irStruct = new IrStruct(ts);
|
||||||
|
ts->ir.type = new llvm::PATypeHolder(llvm::OpaqueType::get());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bool ispacked = (ts->alignsize() == 1);
|
bool ispacked = (ts->alignsize() == 1);
|
||||||
|
|
||||||
IrStruct* irstruct = new IrStruct(ts);
|
IrStruct* irstruct = new IrStruct(ts);
|
||||||
|
|||||||
+3
-3
@@ -129,10 +129,10 @@ DValue* VarExp::toElem(IRState* p)
|
|||||||
if (vd->isDataseg() || (vd->storage_class & STCextern)) {
|
if (vd->isDataseg() || (vd->storage_class & STCextern)) {
|
||||||
vd->toObjFile(0); // TODO: multiobj
|
vd->toObjFile(0); // TODO: multiobj
|
||||||
}
|
}
|
||||||
if (!vd->ir.isSet() || !vd->ir.getIrValue() || DtoType(vd->type)->isAbstract()) {
|
if (!vd->ir.isSet() || !vd->ir.getIrValue()) {
|
||||||
error("global variable %s not resolved", vd->toChars());
|
error("variable %s not resolved", vd->toChars());
|
||||||
if (Logger::enabled())
|
if (Logger::enabled())
|
||||||
Logger::cout() << "unresolved global had type: " << *DtoType(vd->type) << '\n';
|
Logger::cout() << "unresolved variable had type: " << *DtoType(vd->type) << '\n';
|
||||||
fatal();
|
fatal();
|
||||||
}
|
}
|
||||||
if (vd->isDataseg() || (vd->storage_class & STCextern)) {
|
if (vd->isDataseg() || (vd->storage_class & STCextern)) {
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
struct Foo;
|
||||||
|
|
||||||
|
Foo* foo()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
Foo* f = foo();
|
||||||
|
assert(f is null);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user