From 487a8c5f725f831f47e96c7417d50ed765daa22b Mon Sep 17 00:00:00 2001 From: RazvanN7 Date: Tue, 20 Nov 2018 16:59:27 +0200 Subject: [PATCH] Fix Issue 19415 - return non-copyable struct fails if member function has return attribute --- src/dmd/mtype.d | 4 +++- test/compilable/test19145.d | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/compilable/test19145.d 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 +}