ClangCodeModel: Fix another output argument mis-detection

We need to relax the range check: In expressions such as x.y->z, the
second argument for the operator->call is x.y, not just y.

Fixes: QTCREATORBUG-27352
Change-Id: Ida542c11c129630f0a1d301508ec5f8076eb9902
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2022-04-08 16:29:36 +02:00
parent d2e1590aec
commit 06ce449a01
3 changed files with 12 additions and 1 deletions

View File

@@ -2735,7 +2735,7 @@ static void semanticHighlighter(QFutureInterface<HighlightingResult> &future,
// The callable is never displayed as an output parameter. // The callable is never displayed as an output parameter.
// TODO: A good argument can be made to display objects on which a non-const // TODO: A good argument can be made to display objects on which a non-const
// operator or function is called as output parameters. // operator or function is called as output parameters.
if (children.at(1).range() == range) if (children.at(1).range().contains(range))
return false; return false;
QList<AstNode> firstChildTree{children.first()}; QList<AstNode> firstChildTree{children.first()};

View File

@@ -1321,6 +1321,8 @@ void ClangdTestHighlighting::test_data()
<< QList<int>{C_FIELD} << 0; << QList<int>{C_FIELD} << 0;
QTest::newRow("member call on dependent (3)") << 999 << 9 << 999 << 12 QTest::newRow("member call on dependent (3)") << 999 << 9 << 999 << 12
<< QList<int>{C_LOCAL} << 0; << QList<int>{C_LOCAL} << 0;
QTest::newRow("member access via operator->") << 1009 << 7 << 1009 << 21
<< QList<int>{C_FIELD} << 0;
} }
void ClangdTestHighlighting::test() void ClangdTestHighlighting::test()

View File

@@ -999,3 +999,12 @@ public:
ptr->bar(); ptr->bar();
} }
}; };
namespace std { template<typename T> struct optional { T* operator->(); }; }
struct structWithData { int value; };
struct structWithOptional { std::optional<structWithData> opt_my_struct1; };
void foo(structWithOptional & s)
{
s.opt_my_struct1->value = 5;
}