ClangCodeModel: Fix erroneous highlighting with clangd

In certain cases, members being initialized were highlighted as output
parameters.

Task-number: QTCREATORBUG-27059
Change-Id: I0de8aee5e4db735251a314b14af04459e6ac772c
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2022-02-15 11:05:28 +01:00
parent b1f35bf905
commit a189a74dea
3 changed files with 21 additions and 0 deletions

View File

@@ -2667,6 +2667,11 @@ static void semanticHighlighter(QFutureInterface<HighlightingResult> &future,
const QList<AstNode> path = getAstPath(ast, range);
if (path.size() < 2)
return false;
if (token.type == "property"
&& (path.rbegin()->kind() == "MemberInitializer"
|| path.rbegin()->kind() == "CXXConstruct")) {
return false;
}
for (auto it = path.rbegin() + 1; it != path.rend(); ++it) {
if (it->kind() == "Call" || it->kind() == "CXXConstruct"
|| it->kind() == "MemberInitializer") {

View File

@@ -1288,6 +1288,10 @@ void ClangdTestHighlighting::test_data()
<< QList<int>{C_LOCAL} << 0;
QTest::newRow("const operator()") << 903 << 5 << 903 << 7
<< QList<int>{C_LOCAL} << 0;
QTest::newRow("member initialization: member (user-defined type)") << 911 << 14 << 911 << 18
<< QList<int>{C_FIELD} << 0;
QTest::newRow("member initialization: member (built-in type)") << 911 << 23 << 911 << 27
<< QList<int>{C_FIELD} << 0;
}
void ClangdTestHighlighting::test()

View File

@@ -902,3 +902,15 @@ void callOperators()
Callable2 c2;
c2();
}
namespace std { template<typename T> struct atomic { atomic(int) {} }; }
void constructorMemberInitialization()
{
struct S {
S(): m_m1(1), m_m2(0) {}
std::atomic<int> m_m1;
int m_m2;
};
}