ClangCodeModel: Fix erroneous highlighting as output argument

... for objects with non-const member calls.
Amends 8247f4f3dd.

Fixes: QTCREATORBUG-27306
Change-Id: I13fdf1ff9daf9ac084beda6c1d8ada5801adca4c
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2022-04-04 12:01:39 +02:00
parent 0c35d79e39
commit 25144c0afe
3 changed files with 35 additions and 2 deletions

View File

@@ -2707,9 +2707,15 @@ static void semanticHighlighter(QFutureInterface<HighlightingResult> &future,
if (path.rbegin()->hasConstType())
return false;
for (auto it = path.rbegin() + 1; it != path.rend(); ++it) {
if (it->kind() == "Call" || it->kind() == "CXXConstruct"
|| it->kind() == "MemberInitializer") {
if (it->kind() == "CXXConstruct" || it->kind() == "MemberInitializer")
return true;
if (it->kind() == "Call") {
// In class templates, member calls can result in "Call" nodes rather than
// "CXXMemberCall". We try to detect this by checking for a certain kind of
// child node.
const QList<AstNode> children = it->children().value_or(QList<AstNode>());
return children.isEmpty() || children.first().kind() != "CXXDependentScopeMember";
}
// The token should get marked for e.g. lambdas, but not for assignment operators,

View File

@@ -1315,6 +1315,12 @@ void ClangdTestHighlighting::test_data()
QTest::newRow("deref operator (object)") << 960 << 10 << 960 << 11 << QList<int>{C_LOCAL} << 0;
QTest::newRow("deref operator (member)") << 960 << 12 << 960 << 13 << QList<int>{C_FIELD} << 0;
QTest::newRow("nested call") << 979 << 20 << 979 << 21 << QList<int>{C_LOCAL} << 0;
QTest::newRow("member call on dependent (1)") << 996 << 19 << 996 << 22
<< QList<int>{C_FIELD} << 0;
QTest::newRow("member call on dependent (2)") << 996 << 38 << 996 << 41
<< QList<int>{C_FIELD} << 0;
QTest::newRow("member call on dependent (3)") << 999 << 9 << 999 << 12
<< QList<int>{C_LOCAL} << 0;
}
void ClangdTestHighlighting::test()

View File

@@ -978,3 +978,24 @@ void nestedCall()
my_struct* s = get_my_struct();
new my_struct2(s->method(0));
}
template<typename T>
class my_class
{
private:
struct my_int
{
int n;
};
std::vector<my_int> vec;
public:
void foo()
{
auto it = vec.begin(), end = vec.end();
T* ptr = nullptr;
ptr->bar();
}
};