diff --git a/src/dmd/mtype.d b/src/dmd/mtype.d index bdfa326e5c33..f47d26316ca6 100644 --- a/src/dmd/mtype.d +++ b/src/dmd/mtype.d @@ -5506,7 +5506,9 @@ extern (C++) final class TypeStruct : Type // Probably should cache this information in sym rather than recompute StructDeclaration s = sym; - sym.size(Loc.initial); // give error for forward references + if (sym.members && !sym.determineFields() && sym.type != Type.terror) + error(sym.loc, "no size because of forward references"); + foreach (VarDeclaration v; s.fields) { if (v.storage_class & STC.ref_ || v.hasPointers()) diff --git a/test/compilable/test19145.d b/test/compilable/test19145.d new file mode 100644 index 000000000000..ef5faa840f7b --- /dev/null +++ b/test/compilable/test19145.d @@ -0,0 +1,14 @@ +// https://issues.dlang.org/show_bug.cgi?id=19415 + +struct S +{ + int x; + S foo() return { return S(x); } + this(this) @disable; +} + +S bar() +{ + S s; + return s; // Error: struct `S` is not copyable because it is annotated with @disable +}