moc: Do not get confused by constexpr token in functions

Surprisingly, moc had no awareness of constexpr at all. This would still
mostly work, as we were just skipping it, except for the case where
constexpr appears as the last keyword – in which case we'd pick it up as
the type name.

Fix this by adding constexpr as a known token, and add it to the list of things we ignore in testForFunctionModifiers.

Pick-to: 6.5 6.8
Fixes: QTBUG-122609
Change-Id: I0ae0c0477e611ff83fbb841233035bea52216be2
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Fabian Kosmale 2024-11-29 09:17:37 +01:00
parent 577946c1f0
commit 984ad9019a
5 changed files with 469 additions and 454 deletions

File diff suppressed because it is too large Load Diff

View File

@ -527,7 +527,7 @@ bool Moc::parseFunction(FunctionDef *def, bool inMacro)
bool Moc::testForFunctionModifiers(FunctionDef *def)
{
return test(EXPLICIT) || test(INLINE) ||
return test(EXPLICIT) || test(INLINE) || test(CONSTEXPR) ||
(test(STATIC) && (def->isStatic = true)) ||
(test(VIRTUAL) && (def->isVirtual = true));
}

View File

@ -64,6 +64,7 @@ QT_BEGIN_NAMESPACE
F(EXPLICIT) \
F(STATIC) \
F(CONST) \
F(CONSTEXPR) \
F(VOLATILE) \
F(OPERATOR) \
F(SIZEOF) \

View File

@ -121,6 +121,7 @@ static const Keyword keywords[] = {
{ "explicit", "EXPLICIT" },
{ "static", "STATIC" },
{ "const", "CONST" },
{ "constexpr", "CONSTEXPR" },
{ "volatile", "VOLATILE" },
{ "operator", "OPERATOR" },
{ "sizeof", "SIZEOF" },

View File

@ -675,6 +675,7 @@ public:
{ return *this; }
Q_INVOKABLE const QObject& myInvokableReturningConstRef() const
{ return *this; }
Q_INVOKABLE static int inline constexpr invokableWithConstexpr() { return 42; }
// that one however should be fine