forked from qt-creator/qt-creator
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:
@@ -273,9 +273,9 @@ const Name *LookupContext::minimalName(Symbol *symbol, ClassOrNamespace *target,
|
|||||||
ClassOrNamespace *current = target;
|
ClassOrNamespace *current = target;
|
||||||
|
|
||||||
const auto getNameFromItems = [symbol, target, control](const QList<LookupItem> &items,
|
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) {
|
for (const LookupItem &item : items) {
|
||||||
if (checkSymbols && !symbolIdentical(item.declaration(), symbol))
|
if (!symbol->asUsingDeclaration() && !symbolIdentical(item.declaration(), symbol))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// eliminate inline namespaces
|
// 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
|
// once we're qualified enough to get the same symbol, break
|
||||||
if (target) {
|
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)
|
if (minimal)
|
||||||
return minimal;
|
return minimal;
|
||||||
}
|
}
|
||||||
@@ -312,7 +312,7 @@ const Name *LookupContext::minimalName(Symbol *symbol, ClassOrNamespace *target,
|
|||||||
const QList<ClassOrNamespace *> usings = nested->usings();
|
const QList<ClassOrNamespace *> usings = nested->usings();
|
||||||
for (ClassOrNamespace * const u : usings) {
|
for (ClassOrNamespace * const u : usings) {
|
||||||
const Name * const minimal = getNameFromItems(u->lookup(symbol->name()),
|
const Name * const minimal = getNameFromItems(u->lookup(symbol->name()),
|
||||||
nameList, false);
|
nameList);
|
||||||
if (minimal)
|
if (minimal)
|
||||||
return minimal;
|
return minimal;
|
||||||
}
|
}
|
||||||
|
@@ -4404,6 +4404,32 @@ void @func(const N1::S &s);
|
|||||||
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);
|
testDocuments << QuickFixTestDocument::create("file.cpp", original, expected);
|
||||||
|
Reference in New Issue
Block a user