From 1f2e25dd48e4fda13b74f337e4e5cb6769bf89e7 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 24 Nov 2021 16:03:38 +0100 Subject: [PATCH] ClangCodeModel: Tighten the check for ambiguous calls ... when doing "Follow Symbol" with clangd. Not every call to a virtual function is ambiguous. Amends 4fe5be2565. Change-Id: I7c31644510ca85d430a3e18b2ccad97548f71d54 Reviewed-by: Reviewed-by: David Schulz --- src/plugins/clangcodemodel/clangdclient.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index 68a94b1fea9..da999910c18 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -3674,7 +3674,13 @@ void ExtraHighlightingResultsCollector::visitNode(const AstNode &node) bool ClangdClient::FollowSymbolData::defLinkIsAmbiguous() const { - // If we have up-to-date highlighting info, we can give a definite answer. + // Even if the call is to a virtual function, it might not be ambiguous: + // class A { virtual void f(); }; class B : public A { void f() override { A::f(); } }; + if (!cursorNode->mightBeAmbiguousVirtualCall() && !cursorNode->isPureVirtualDeclaration()) + return false; + + // If we have up-to-date highlighting info, we know whether we are dealing with + // a virtual call. if (editorWidget) { const auto virtualRanges = q->d->virtualRanges.constFind(editorWidget->textDocument()); if (virtualRanges != q->d->virtualRanges.constEnd() @@ -3686,8 +3692,9 @@ bool ClangdClient::FollowSymbolData::defLinkIsAmbiguous() const } } - // Otherwise, we have to rely on AST-based heuristics. - return cursorNode->mightBeAmbiguousVirtualCall() || cursorNode->isPureVirtualDeclaration(); + // Otherwise, we accept potentially doing more work than needed rather than not catching + // possible overrides. + return true; } } // namespace Internal