From 84ab6c1aa1fe4051edb9f96714f0f691d639b725 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Wed, 3 Aug 2022 09:16:27 +0200 Subject: [PATCH] moc: handle attributes in class declarations We already had code to handle attributes on funtcions, but we didn't handle them correctly for classes so far. Fix this by simply skipping over the attribute. Fixes: QTBUG-105310 Pick-to: 5.15 6.2 6.3 6.4 Change-Id: Ic4149f940e74820de4f2fa9540d9dc5b4e626a3a Reviewed-by: Marc Mutz Reviewed-by: Qt CI Bot --- src/tools/moc/moc.cpp | 3 +++ tests/auto/tools/moc/cxx-attributes.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index 8a5abd30201..5e2ba18a005 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -40,6 +40,9 @@ bool Moc::parseClassHead(ClassDef *def) return false; } while (token); + // support attributes like "class [[deprecated]]] name" + skipCxxAttributes(); + if (!test(IDENTIFIER)) // typedef struct { ... } return false; QByteArray name = lexem(); diff --git a/tests/auto/tools/moc/cxx-attributes.h b/tests/auto/tools/moc/cxx-attributes.h index 799a13293cc..6301d7804ca 100644 --- a/tests/auto/tools/moc/cxx-attributes.h +++ b/tests/auto/tools/moc/cxx-attributes.h @@ -10,7 +10,7 @@ QT_WARNING_PUSH QT_WARNING_DISABLE_CLANG("-Wunknown-attributes") QT_WARNING_DISABLE_GCC("-Wattributes") -class CppAttribute : public QObject +class [[deprecated]] CppAttribute : public QObject { Q_OBJECT signals: