aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2023-06-23 11:50:07 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2023-06-29 09:28:52 +0200
commitf7930126a67c59213e88eeb31f275f0b8a5b46a9 (patch)
tree504aa0ec50c9ae2b22bd1f78643882de02ca6699 /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
parent6a074d57ce28a9514a116f71f77e3c4f18ed61e9 (diff)
qml compiler: Detect if user confuses flags and enums
If you pass the enumeration type to the Q_FLAG macro, you'll get an qmltypes entry where the type is marked as a flag, but where aliasName is empty. For backwards compatibility reasons, we cannot static_assert that the type passed into QFlags is actually a flag type. When using the interpreter, this does not cause any issues, because the code there does not need to distinguish flags and enums. When compilation is enabled, we do however generate bogus code, which either leads to a wrong result, or to a crash if ASAN is enabled. Avoid the issue by detecting that the enum is missing, and by rejecting that case. Pick-to: 6.6 6.5 Fixes: QTBUG-114326 Change-Id: If5cb801b3cf2c3bd7986ef0c8fc3664e6ed564b8 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 5e4a576846..f4e8d31f5a 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -68,6 +68,7 @@ private slots:
void enumConversion();
void enumFromBadSingleton();
void enumLookup();
+ void enumMarkedAsFlag();
void enumProblems();
void enumScope();
void enums();
@@ -1291,6 +1292,17 @@ void tst_QmlCppCodegen::enumLookup()
QCOMPARE(o->property("ready").toBool(), true);
}
+void tst_QmlCppCodegen::enumMarkedAsFlag()
+{
+ QQmlEngine engine;
+
+ QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/enumMarkedAsFlag.qml"_s));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+
+ QCOMPARE(o->property("flagValue").toInt(), 3);
+}
+
void tst_QmlCppCodegen::enumProblems()
{
QQmlEngine engine;