CplusPlus: Fix minimal name construction

... when creating the constructor implementation for a derived class.
We would erroneously strip off the class name.
Amends aae3ce15aa.

Change-Id: I62c800d490626e8cb9416829633f9ef7b0c666cd
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2021-02-08 16:24:39 +01:00
parent cb5977fbad
commit e740295b8d
2 changed files with 30 additions and 4 deletions

View File

@@ -273,9 +273,9 @@ const Name *LookupContext::minimalName(Symbol *symbol, ClassOrNamespace *target,
ClassOrNamespace *current = target;
const auto getNameFromItems = [symbol, target, control](const QList<LookupItem> &items,
const QList<const Name *> &names, bool checkSymbols) -> const Name * {
const QList<const Name *> &names) -> const Name * {
for (const LookupItem &item : items) {
if (checkSymbols && !symbolIdentical(item.declaration(), symbol))
if (!symbol->asUsingDeclaration() && !symbolIdentical(item.declaration(), symbol))
continue;
// eliminate inline namespaces
@@ -300,7 +300,7 @@ const Name *LookupContext::minimalName(Symbol *symbol, ClassOrNamespace *target,
// once we're qualified enough to get the same symbol, break
if (target) {
const Name * const minimal = getNameFromItems(target->lookup(n), names.mid(i), true);
const Name * const minimal = getNameFromItems(target->lookup(n), names.mid(i));
if (minimal)
return minimal;
}
@@ -312,7 +312,7 @@ const Name *LookupContext::minimalName(Symbol *symbol, ClassOrNamespace *target,
const QList<ClassOrNamespace *> usings = nested->usings();
for (ClassOrNamespace * const u : usings) {
const Name * const minimal = getNameFromItems(u->lookup(symbol->name()),
nameList, false);
nameList);
if (minimal)
return minimal;
}

View File

@@ -4404,6 +4404,32 @@ void @func(const N1::S &s);
void func(const N1::S &s)
{
}
)";
testDocuments << QuickFixTestDocument::create("file.cpp", original, expected);
QuickFixOperationTest(testDocuments, &factory);
// No using declarations here, but the code model has one. No idea why.
testDocuments.clear();
original = R"(
class B {};
class D : public B {
@D();
};
)";
expected = original;
testDocuments << QuickFixTestDocument::create("file.h", original, expected);
// Source File
original = R"(
#include "file.h"
)";
expected = R"(
#include "file.h"
D::D()
{
}
)";
testDocuments << QuickFixTestDocument::create("file.cpp", original, expected);