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: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2021-11-24 16:03:38 +01:00
parent 72cd43594c
commit 1f2e25dd48

View File

@@ -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