forked from qt-creator/qt-creator
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:
@@ -2707,9 +2707,15 @@ static void semanticHighlighter(QFutureInterface<HighlightingResult> &future,
|
|||||||
if (path.rbegin()->hasConstType())
|
if (path.rbegin()->hasConstType())
|
||||||
return false;
|
return false;
|
||||||
for (auto it = path.rbegin() + 1; it != path.rend(); ++it) {
|
for (auto it = path.rbegin() + 1; it != path.rend(); ++it) {
|
||||||
if (it->kind() == "Call" || it->kind() == "CXXConstruct"
|
if (it->kind() == "CXXConstruct" || it->kind() == "MemberInitializer")
|
||||||
|| it->kind() == "MemberInitializer") {
|
|
||||||
return true;
|
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,
|
// The token should get marked for e.g. lambdas, but not for assignment operators,
|
||||||
|
@@ -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 (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("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("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()
|
void ClangdTestHighlighting::test()
|
||||||
|
@@ -978,3 +978,24 @@ void nestedCall()
|
|||||||
my_struct* s = get_my_struct();
|
my_struct* s = get_my_struct();
|
||||||
new my_struct2(s->method(0));
|
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();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Reference in New Issue
Block a user