From 260095c92419e81a07fe031fdd002efc84afec0f Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Tue, 12 Apr 2022 11:50:12 +0200 Subject: [PATCH] ClangCodeModel: Fix another false positive ... in output argument highlighting. If there is not enough information for clang to determine the const-ness of the argument passing (as it can happen in templates), do not report an output argument. Change-Id: I8d0143042f02ac44d8d971398014828cff14697f Reviewed-by: Reviewed-by: Qt CI Bot Reviewed-by: David Schulz --- src/plugins/clangcodemodel/clangdclient.cpp | 6 +++++- src/plugins/clangcodemodel/test/clangdtests.cpp | 2 ++ .../test/data/highlighting/highlighting.cpp | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index 6d283f34f4a..5ce913a5a3a 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -2712,8 +2712,12 @@ static void semanticHighlighter(QFutureInterface &future, if (it->kind() == "Call") { // The first child is e.g. a called lambda or an object on which // the call happens, and should not be highlighted as an output argument. + // If the call is not fully resolved (as in templates), we don't + // know whether the argument is passed as const or not. const QList children = it->children().value_or(QList()); - return children.isEmpty() || children.first().range() != (it - 1)->range(); + return children.isEmpty() + || (children.first().range() != (it - 1)->range() + && children.first().kind() != "UnresolvedLookup"); } // The token should get marked for e.g. lambdas, but not for assignment operators, diff --git a/src/plugins/clangcodemodel/test/clangdtests.cpp b/src/plugins/clangcodemodel/test/clangdtests.cpp index d3a27b87bd5..c0b0805ca32 100644 --- a/src/plugins/clangcodemodel/test/clangdtests.cpp +++ b/src/plugins/clangcodemodel/test/clangdtests.cpp @@ -1327,6 +1327,8 @@ void ClangdTestHighlighting::test_data() << QList{C_LOCAL} << 0; QTest::newRow("call on inherited member") << 1024 << 9 << 1024 << 12 << QList{C_FIELD} << 0; + QTest::newRow("pass inherited member by value") << 1038 << 21 << 1038 << 26 + << 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 9dbb08db93d..cd4ecb46cec 100644 --- a/src/plugins/clangcodemodel/test/data/highlighting/highlighting.cpp +++ b/src/plugins/clangcodemodel/test/data/highlighting/highlighting.cpp @@ -1024,3 +1024,19 @@ template class Derived : public BaseWithMember vec.clear(); } }; + +static bool testVal(int val); +class BaseWithMember2 +{ +protected: + int value; +}; +template class Derived2 : public BaseWithMember2 +{ + bool foo() + { + if (testVal(value)) + return true; + return false; + } +};