From 16d1ddfc42732afc6ba90df66042c7ff4be348c2 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sat, 11 Mar 2017 19:39:32 +0100 Subject: moc: Support signals that return movable-only type By adding std::move where it makes sense. This is not only good for move-only types, but for any type which can be moved as it saves copies of the return value in any case. [ChangeLog][moc] Move-only types are now supported as return types of signals and slots. Change-Id: Idc9453af993e7574a6bddd4a87210eddd3da48a9 Reviewed-by: Marc Mutz --- src/tools/moc/generator.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/tools/moc/generator.cpp') diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index db27067cf6..c4184929ef 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -1193,7 +1193,7 @@ void Generator::generateStaticMetacall() } fprintf(out, ");"); if (f.normalizedType != "void") { - fprintf(out, "\n if (_a[0]) *reinterpret_cast< %s*>(_a[0]) = _r; } ", + fprintf(out, "\n if (_a[0]) *reinterpret_cast< %s*>(_a[0]) = std::move(_r); } ", noRef(f.normalizedType).constData()); isUsed_a = true; } @@ -1506,11 +1506,7 @@ void Generator::generateSignal(FunctionDef *def,int index) fprintf(out, ")%s\n{\n", constQualifier); if (def->type.name.size() && def->normalizedType != "void") { QByteArray returnType = noRef(def->normalizedType); - if (returnType.endsWith('*')) { - fprintf(out, " %s _t0 = 0;\n", returnType.constData()); - } else { - fprintf(out, " %s _t0 = %s();\n", returnType.constData(), returnType.constData()); - } + fprintf(out, " %s _t0{};\n", returnType.constData()); } fprintf(out, " void *_a[] = { "); -- cgit v1.2.3