From 1c42160f643ba3e0fc0d4fbaa24a8d357ae24965 Mon Sep 17 00:00:00 2001 From: k-hara Date: Sun, 29 Sep 2013 14:49:42 +0900 Subject: [PATCH] fix Issue 7892 - Compiler-generated struct copies can result in errors when ctor is @disable'd --- src/declaration.c | 5 +++-- test/runnable/testcontracts.d | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/declaration.c b/src/declaration.c index 02e7a5ea7caa..f940f6c3eb5e 100644 --- a/src/declaration.c +++ b/src/declaration.c @@ -1296,11 +1296,12 @@ void VarDeclaration::semantic(Scope *sc) } } - if (!(storage_class & (STCctfe | STCref)) && tbn->ty == Tstruct && + if (!(storage_class & (STCctfe | STCref | STCresult)) && tbn->ty == Tstruct && ((TypeStruct *)tbn)->sym->noDefaultCtor) { if (!init) - { if (isField()) + { + if (isField()) /* For fields, we'll check the constructor later to make sure it is initialized */ storage_class |= STCnodefaultctor; diff --git a/test/runnable/testcontracts.d b/test/runnable/testcontracts.d index 19287d7f419c..5433c028d0ec 100644 --- a/test/runnable/testcontracts.d +++ b/test/runnable/testcontracts.d @@ -457,6 +457,36 @@ class DC7883 : CC7883 body { return 1; } } +/*******************************************/ +// 7892 + +struct S7892 +{ + @disable this(); + this(int x) {} +} + +S7892 f7892() +out (result) {} // case 1 +body +{ + return S7892(1); +} + +interface I7892 +{ + S7892 f(); +} +class C7892 +{ + invariant() {} // case 2 + + S7892 f() + { + return S7892(1); + } +} + /*******************************************/ // 8066