diff options
author | MÃ¥rten Nordheim <marten.nordheim@qt.io> | 2020-04-23 15:32:32 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-05-04 09:51:02 +0000 |
commit | 4fd10b68d4ec813b031415872e2ab296a062fb6f (patch) | |
tree | d9000a9d014237bf59a62670c3407827b87362b6 /src | |
parent | 207b9346f78ab776507c275c68efe91cf18b4191 (diff) |
Moc: parse trailing return type
Fixes: QTBUG-71123
Change-Id: I1c3749f0892fddcc433c9afcb1d6d7c30c97c9d9
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 12b8283f899ebcf401d974927314b9531334a56e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/moc/moc.cpp | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index a66eda6f86..c8fe0e9a83 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -198,6 +198,7 @@ Type Moc::parseType() case DOUBLE: case VOID: case BOOL: + case AUTO: type.name += lexem(); isVoid |= (lookup(0) == VOID); break; @@ -467,15 +468,6 @@ bool Moc::parseFunction(FunctionDef *def, bool inMacro) scopedFunctionName = tempType.isScoped; } - // we don't support references as return types, it's too dangerous - if (def->type.referenceType == Type::Reference) { - QByteArray rawName = def->type.rawName; - def->type = Type("void"); - def->type.rawName = rawName; - } - - def->normalizedType = normalizeType(def->type.name); - if (!test(RPAREN)) { parseFunctionArguments(def); next(RPAREN); @@ -498,6 +490,10 @@ bool Moc::parseFunction(FunctionDef *def, bool inMacro) next(LPAREN); until(RPAREN); } + + if (def->type.name == "auto" && test(ARROW)) + def->type = parseType(); // Parse trailing return-type + if (test(SEMIC)) ; else if ((def->inlineCode = test(LBRACE))) @@ -515,6 +511,22 @@ bool Moc::parseFunction(FunctionDef *def, bool inMacro) warning(msg.constData()); return false; } + + QList<QByteArray> typeNameParts = normalizeType(def->type.name).split(' '); + if (typeNameParts.contains("auto")) { + // We expected a trailing return type but we haven't seen one + error("Function declared with auto as return type but missing trailing return type. " + "Return type deduction is not supported."); + } + + // we don't support references as return types, it's too dangerous + if (def->type.referenceType == Type::Reference) { + QByteArray rawName = def->type.rawName; + def->type = Type("void"); + def->type.rawName = rawName; + } + + def->normalizedType = normalizeType(def->type.name); return true; } |