diff --git a/src/typinf.c b/src/typinf.c index 1445b445e533..0321841d7aac 100644 --- a/src/typinf.c +++ b/src/typinf.c @@ -407,7 +407,7 @@ class TypeInfoDtVisitor : public Visitor void visit(TypeInfoStructDeclaration *d) { - //printf("TypeInfoStructDeclaration::toDt() '%s'\n", toChars()); + //printf("TypeInfoStructDeclaration::toDt() '%s'\n", d->toChars()); if (global.params.is64bit) verifyStructSize(Type::typeinfostruct, 17 * Target::ptrsize); else @@ -424,6 +424,17 @@ class TypeInfoDtVisitor : public Visitor if (!sd->members) return; + if (TemplateInstance *ti = sd->isInstantiated()) + { + /* Bugzilla 14425: TypeInfo_Struct would refer the members of + * struct (e.g. opEquals via xopEquals field), so if it's instantiated + * in speculative context, TypeInfo creation should also be + * stopped to avoid 'unresolved symbol' linker errors. + */ + if (!ti->needsCodegen() && !ti->minst) + return; + } + /* Put out: * char[] name; * void[] init; diff --git a/test/runnable/link14425.d b/test/runnable/link14425.d new file mode 100644 index 000000000000..f35fa9117368 --- /dev/null +++ b/test/runnable/link14425.d @@ -0,0 +1,9 @@ +struct SFoo(I) { I i; } +struct SBar(I) { I i; } +static assert(is(SFoo!(SBar!string))); + +class CFoo(I) { I i; } +class CBar(I) { I i; } +static assert(is(CFoo!(CBar!string))); + +void main() {}