From 69fb18357c8495b58dba04960629f1f21eed3618 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Thu, 26 Jun 2025 15:05:52 +0200 Subject: compiler: Avoid invalid C++ code generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit inlineConsoleMethod's stringConversion needs to create a string, so that we can later append to it. Because we were missing parentheses, this did not happen, and we would end up with code looking like u']'.append(...) which obviously isn't valid C++. Fix this by always adding parentheses around the expression. Found while trying to prove that QTBUG-109279 was fixed. Task-number: QTBUG-109279 Pick-to: 6.10 6.9 Change-Id: I67fce5b2c1f1460a5d6b617824f3c36f9804ea76 Reviewed-by: Olivier De Cannière --- tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp') diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 708e835f46..00c00b4c0f 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -1223,13 +1223,18 @@ void tst_QmlCppCodegen::consoleObject() const QRegularExpression re2(u"QQmlComponentAttached\\(0x[0-9a-f]+\\)"_s); QTest::ignoreMessage(QtDebugMsg, re2); + QTest::ignoreMessage(QtDebugMsg, "[1,2,3,4,5] true"); + QScopedPointer o(c.create()); QVERIFY(!o.isNull()); auto oldHandler = qInstallMessageHandler( - [](QtMsgType, const QMessageLogContext &ctxt, const QString &) { + [](QtMsgType, const QMessageLogContext &ctxt, const QString &msg) { QCOMPARE(ctxt.file, urlString.toUtf8()); - QCOMPARE(ctxt.function, QByteArray("expression for onCompleted")); + if (msg == QString(u"[1,2,3,4,5] true")) + QCOMPARE(ctxt.function, QByteArray("xyz")); + else + QCOMPARE(ctxt.function, QByteArray("expression for onCompleted")); QVERIFY(ctxt.line > 0); }); const auto guard = qScopeGuard([oldHandler]() { qInstallMessageHandler(oldHandler); }); -- cgit v1.2.3