forked from qt-creator/qt-creator
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:
@@ -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") {
|
||||
|
@@ -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()
|
||||
|
@@ -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;
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user