# HG changeset patch # User Tomas Lindquist Olsen # Date 1223294815 -7200 # Node ID a15ccbf7451db129e5890502aec15e87f68d6033 # Parent 93433f4b6963bca3efc531501a76e6852c1e3ce5 Support structs that are merely a forward reference. See mini/forwdecl1.d diff -r 93433f4b6963 -r a15ccbf7451d gen/structs.cpp --- a/gen/structs.cpp Mon Oct 06 12:46:57 2008 +0200 +++ b/gen/structs.cpp Mon Oct 06 14:06:55 2008 +0200 @@ -131,10 +131,16 @@ Logger::println("DtoResolveStruct(%s): %s", sd->toChars(), sd->loc.toChars()); 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); diff -r 93433f4b6963 -r a15ccbf7451d gen/toir.cpp --- a/gen/toir.cpp Mon Oct 06 12:46:57 2008 +0200 +++ b/gen/toir.cpp Mon Oct 06 14:06:55 2008 +0200 @@ -129,10 +129,10 @@ if (vd->isDataseg() || (vd->storage_class & STCextern)) { vd->toObjFile(0); // TODO: multiobj } - if (!vd->ir.isSet() || !vd->ir.getIrValue() || DtoType(vd->type)->isAbstract()) { - error("global variable %s not resolved", vd->toChars()); + if (!vd->ir.isSet() || !vd->ir.getIrValue()) { + error("variable %s not resolved", vd->toChars()); if (Logger::enabled()) - Logger::cout() << "unresolved global had type: " << *DtoType(vd->type) << '\n'; + Logger::cout() << "unresolved variable had type: " << *DtoType(vd->type) << '\n'; fatal(); } if (vd->isDataseg() || (vd->storage_class & STCextern)) { diff -r 93433f4b6963 -r a15ccbf7451d tests/mini/forwdecl1.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/mini/forwdecl1.d Mon Oct 06 14:06:55 2008 +0200 @@ -0,0 +1,12 @@ +struct Foo; + +Foo* foo() +{ + return null; +} + +void main() +{ + Foo* f = foo(); + assert(f is null); +}