CppEditor: Add support for init statements in if conditions

Fixes: QTCREATORBUG-29182
Change-Id: I9b7969da694b368236246123ad0028d8e754e903
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2023-05-24 15:18:48 +02:00
parent 07764bdf15
commit c8f29b9e01
9 changed files with 68 additions and 6 deletions

View File

@@ -150,6 +150,7 @@ private Q_SLOTS:
void requiresClause();
void coroutines();
void genericLambdas();
void ifStatementWithInitialization();
};
@@ -550,5 +551,27 @@ int main()
QVERIFY(!hasErrors);
}
void tst_cxx11::ifStatementWithInitialization()
{
LanguageFeatures features;
features.cxxEnabled = true;
features.cxx11Enabled = features.cxx14Enabled = features.cxx17Enabled = true;
const QString source = R"(
int main()
{
if (bool b = true; b)
b = false;
}
)";
QByteArray errors;
Document::Ptr doc = Document::create(FilePath::fromPathPart(u"testFile"));
processDocument(doc, source.toUtf8(), features, &errors);
const bool hasErrors = !errors.isEmpty();
if (hasErrors)
qDebug().noquote() << errors;
QVERIFY(!hasErrors);
}
QTEST_APPLESS_MAIN(tst_cxx11)
#include "tst_cxx11.moc"