From 7f9d2137654de0ee041c74cbccb958a3a803996c Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Fri, 16 Jun 2023 13:25:42 +0200 Subject: [PATCH] moc: Drop support for function declaration without type specifier Neither C++ nor modern C allow omitting the type (which used to be equivalent to an "int" return type). moc should not try to parse functions in C code, as they cannot be meta-methods. So there is no point in supporting it. Change-Id: I2b3a492988f29e8139311db64be110581cc1a4de Reviewed-by: Volker Hilsheimer Reviewed-by: Thiago Macieira --- src/tools/moc/moc.cpp | 51 +++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index ee15427e1c..cc5cc929b9 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -423,35 +423,29 @@ bool Moc::parseFunction(FunctionDef *def, bool inMacro) error(); } bool scopedFunctionName = false; - if (test(LPAREN)) { - def->name = def->type.name; - scopedFunctionName = def->type.isScoped; - def->type = Type("int"); - } else { - // we might have modifiers and attributes after a tag - // note that testFunctionAttribute is handled further below, - // and revisions and attributes must come first - while (testForFunctionModifiers(def)) {} - Type tempType = parseType();; - while (!tempType.name.isEmpty() && lookup() != LPAREN) { - if (testFunctionAttribute(def->type.firstToken, def)) - ; // fine - else if (def->type.firstToken == Q_SIGNALS_TOKEN) - error(); - else if (def->type.firstToken == Q_SLOTS_TOKEN) - error(); - else { - if (!def->tag.isEmpty()) - def->tag += ' '; - def->tag += def->type.name; - } - def->type = tempType; - tempType = parseType(); + // we might have modifiers and attributes after a tag + // note that testFunctionAttribute is handled further below, + // and revisions and attributes must come first + while (testForFunctionModifiers(def)) {} + Type tempType = parseType();; + while (!tempType.name.isEmpty() && lookup() != LPAREN) { + if (testFunctionAttribute(def->type.firstToken, def)) + ; // fine + else if (def->type.firstToken == Q_SIGNALS_TOKEN) + error(); + else if (def->type.firstToken == Q_SLOTS_TOKEN) + error(); + else { + if (!def->tag.isEmpty()) + def->tag += ' '; + def->tag += def->type.name; } - next(LPAREN, "Not a signal or slot declaration"); - def->name = tempType.name; - scopedFunctionName = tempType.isScoped; + def->type = tempType; + tempType = parseType(); } + next(LPAREN, "Not a signal or slot declaration"); + def->name = tempType.name; + scopedFunctionName = tempType.isScoped; if (!test(RPAREN)) { parseFunctionArguments(def); @@ -543,7 +537,8 @@ bool Moc::parseMaybeFunction(const ClassDef *cdef, FunctionDef *def) def->isConstructor = !tilde; def->type = Type(); } else { - def->type = Type("int"); + // missing type name? => Skip + return false; } } else { // ### TODO: The condition before testForFunctionModifiers shoulnd't be necessary,