forked from qt-creator/qt-creator
CPlusPlus: Fix overload resolution involving default arguments
If one of the overloads had additional default arguments, then for each of these, its priority was increased, which does not appear to make any sense. Fixes: QTCREATORBUG-17807 Change-Id: Id5be81ce52c615a424fe4314d2e50385b3fb2b1c Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -849,22 +849,14 @@ bool ResolveExpression::visit(CallAST *ast)
|
||||
int score = 0;
|
||||
|
||||
for (unsigned i = 0, argc = funTy->argumentCount(); i < argc; ++i) {
|
||||
const FullySpecifiedType formalTy = funTy->argumentAt(i)->type();
|
||||
if (i >= unsigned(arguments.size()))
|
||||
break;
|
||||
|
||||
FullySpecifiedType actualTy;
|
||||
if (i < unsigned(arguments.size())) {
|
||||
const FullySpecifiedType formalTy = funTy->argumentAt(i)->type();
|
||||
const QList<LookupItem> actual = arguments.at(i);
|
||||
if (actual.isEmpty())
|
||||
continue;
|
||||
|
||||
actualTy = actual.first().type();
|
||||
} else {
|
||||
actualTy = formalTy;
|
||||
score += 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
score += evaluateFunctionArgument(actualTy, formalTy);
|
||||
score += evaluateFunctionArgument(actual.first().type(), formalTy);
|
||||
}
|
||||
|
||||
sortedResults.insert(LookupMap::value_type(-score, base));
|
||||
|
||||
@@ -979,6 +979,12 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_data()
|
||||
"template<class $T>\n"
|
||||
"using Foo = Bar<@T>;\n"
|
||||
);
|
||||
|
||||
QTest::newRow("shadowed overload with default args") << _(
|
||||
"struct Parent { void disconnect(int n = 0); };\n"
|
||||
"struct Child : public Parent { void $disconnect(); };\n"
|
||||
"void test() { Child c; c.@disconnect(); }\n"
|
||||
);
|
||||
}
|
||||
|
||||
void CppEditorPlugin::test_FollowSymbolUnderCursor()
|
||||
|
||||
Reference in New Issue
Block a user