From 06ce449a01de5d1d7ac52e319cae66d00b9da150 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Fri, 8 Apr 2022 16:29:36 +0200 Subject: [PATCH] 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 Reviewed-by: Reviewed-by: David Schulz --- src/plugins/clangcodemodel/clangdclient.cpp | 2 +- src/plugins/clangcodemodel/test/clangdtests.cpp | 2 ++ .../test/data/highlighting/highlighting.cpp | 9 +++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index e52a79ae4ea..6889d959de7 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -2735,7 +2735,7 @@ static void semanticHighlighter(QFutureInterface &future, // The callable is never displayed as an output parameter. // TODO: A good argument can be made to display objects on which a non-const // operator or function is called as output parameters. - if (children.at(1).range() == range) + if (children.at(1).range().contains(range)) return false; QList firstChildTree{children.first()}; diff --git a/src/plugins/clangcodemodel/test/clangdtests.cpp b/src/plugins/clangcodemodel/test/clangdtests.cpp index 67339c77293..25734316e44 100644 --- a/src/plugins/clangcodemodel/test/clangdtests.cpp +++ b/src/plugins/clangcodemodel/test/clangdtests.cpp @@ -1321,6 +1321,8 @@ void ClangdTestHighlighting::test_data() << QList{C_FIELD} << 0; QTest::newRow("member call on dependent (3)") << 999 << 9 << 999 << 12 << QList{C_LOCAL} << 0; + QTest::newRow("member access via operator->") << 1009 << 7 << 1009 << 21 + << QList{C_FIELD} << 0; } void ClangdTestHighlighting::test() diff --git a/src/plugins/clangcodemodel/test/data/highlighting/highlighting.cpp b/src/plugins/clangcodemodel/test/data/highlighting/highlighting.cpp index 1d4bcce7f8e..2dc1b04436b 100644 --- a/src/plugins/clangcodemodel/test/data/highlighting/highlighting.cpp +++ b/src/plugins/clangcodemodel/test/data/highlighting/highlighting.cpp @@ -999,3 +999,12 @@ public: ptr->bar(); } }; + +namespace std { template struct optional { T* operator->(); }; } +struct structWithData { int value; }; +struct structWithOptional { std::optional opt_my_struct1; }; + +void foo(structWithOptional & s) +{ + s.opt_my_struct1->value = 5; +}