CplusPlus: Try harder to find a class

... when looking up a member function for categorization.
Contrary to our expectation, the first entry in the lookup results is not
necessarily the best fit.

Task-number: QTCREATORBUG-24894
Change-Id: I1ba6dbebeecd8c4a24fa53194996271339018d9c
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
Christian Kandeler
2020-11-06 11:52:41 +01:00
parent d604d5da18
commit 4ad078b73a

View File

@@ -254,7 +254,7 @@ Usage::Type FindUsages::getType(int line, int column, int tokenIndex)
if (call->base_expression == *(callIt - 1)) {
for (auto it = callIt; it != astPath.rbegin(); --it) {
const auto memberAccess = (*it)->asMemberAccess();
if (!memberAccess)
if (!memberAccess || !memberAccess->member_name || !memberAccess->member_name->name)
continue;
if (memberAccess->member_name == *(it - 1))
return Usage::Type::Other;
@@ -273,9 +273,10 @@ Usage::Type FindUsages::getType(int line, int column, int tokenIndex)
if (!klass) {
if (const auto namedType = baseExprType->asNamedType()) {
items = context.lookup(namedType->name(), item->scope());
if (items.isEmpty())
return Usage::Type::Other;
klass = items.first().type()->asClassType();
for (const LookupItem &item : qAsConst(items)) {
if ((klass = item.type()->asClassType()))
break;
}
}
}
if (!klass)