From e740295b8d3251eb149ff469da252de861d70376 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Mon, 8 Feb 2021 16:24:39 +0100 Subject: [PATCH] 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 --- src/libs/cplusplus/LookupContext.cpp | 8 +++---- src/plugins/cppeditor/cppquickfix_test.cpp | 26 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp index 3f5d3c4f342..5eaa04baf4c 100644 --- a/src/libs/cplusplus/LookupContext.cpp +++ b/src/libs/cplusplus/LookupContext.cpp @@ -273,9 +273,9 @@ const Name *LookupContext::minimalName(Symbol *symbol, ClassOrNamespace *target, ClassOrNamespace *current = target; const auto getNameFromItems = [symbol, target, control](const QList &items, - const QList &names, bool checkSymbols) -> const Name * { + const QList &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 usings = nested->usings(); for (ClassOrNamespace * const u : usings) { const Name * const minimal = getNameFromItems(u->lookup(symbol->name()), - nameList, false); + nameList); if (minimal) return minimal; } diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index 5ba0101b399..1c55c7cc0a5 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -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);