diff --git a/src/libs/cplusplus/LookupContext.h b/src/libs/cplusplus/LookupContext.h index d027f53e56d..b7c84d4e253 100644 --- a/src/libs/cplusplus/LookupContext.h +++ b/src/libs/cplusplus/LookupContext.h @@ -111,6 +111,7 @@ private: AlreadyConsideredClassContainer _alreadyConsideredTemplates; #ifdef DEBUG_LOOKUP +public: const Name *_name; #endif // DEBUG_LOOKUP diff --git a/src/libs/cplusplus/ResolveExpression.cpp b/src/libs/cplusplus/ResolveExpression.cpp index 02f8e56a907..65ba9cb2a39 100644 --- a/src/libs/cplusplus/ResolveExpression.cpp +++ b/src/libs/cplusplus/ResolveExpression.cpp @@ -806,7 +806,7 @@ bool ResolveExpression::visit(MemberAccessAST *ast) const int accessOp = tokenKind(ast->access_token); if (ClassOrNamespace *binding = baseExpression(baseResults, accessOp)) - addResults(binding->lookup(memberName)); + addResults(binding->find(memberName)); return false; } diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp index 70d1dd12321..6d0af131469 100644 --- a/src/plugins/cpptools/cppcompletion_test.cpp +++ b/src/plugins/cpptools/cppcompletion_test.cpp @@ -996,7 +996,6 @@ void CppToolsPlugin::test_completion_cyclic_inheritance_data() "};\n" "\n" "Class c;\n" - "c.\n" "@\n" ; completions.append("Class"); @@ -1006,7 +1005,6 @@ void CppToolsPlugin::test_completion_cyclic_inheritance_data() completions.append("class_recurse_t"); QTest::newRow("case: direct cyclic inheritance with templates, more complex situation") << code << completions; - } void CppToolsPlugin::test_completion_enclosing_template_class() diff --git a/tests/auto/cplusplus/findusages/tst_findusages.cpp b/tests/auto/cplusplus/findusages/tst_findusages.cpp index 0137ac51bfd..0cc1381103e 100644 --- a/tests/auto/cplusplus/findusages/tst_findusages.cpp +++ b/tests/auto/cplusplus/findusages/tst_findusages.cpp @@ -79,6 +79,8 @@ private Q_SLOTS: void inlineMethod(); void lambdaCaptureByValue(); void lambdaCaptureByReference(); + void shadowedNames_1(); + void shadowedNames_2(); // Qt keywords void qproperty_1(); @@ -189,6 +191,69 @@ void tst_FindUsages::lambdaCaptureByReference() QCOMPARE(findUsages.usages().size(), 3); } +void tst_FindUsages::shadowedNames_1() +{ + const QByteArray src = "\n" + "int a();\n" + "struct X{ int a(); };\n" + "int X::a() {}\n" + "void f(X x) { x.a(); }\n" + "void g() { a(); }\n" + ; + + Document::Ptr doc = Document::create("shadowedNames_1"); + doc->setUtf8Source(src); + doc->parse(); + doc->check(); + + QVERIFY(doc->diagnosticMessages().isEmpty()); + QCOMPARE(doc->globalSymbolCount(), 5U); + + Snapshot snapshot; + snapshot.insert(doc); + + Declaration *d = doc->globalSymbolAt(0)->asDeclaration(); + QVERIFY(d); + QCOMPARE(d->name()->identifier()->chars(), "a"); + + FindUsages findUsages(src, doc, snapshot); + findUsages(d); + QCOMPARE(findUsages.usages().size(), 2); +} + +void tst_FindUsages::shadowedNames_2() +{ + const QByteArray src = "\n" + "int a();\n" + "struct X{ int a(); };\n" + "int X::a() {}\n" + "void f(X x) { x.a(); }\n" + "void g() { a(); }\n"; + + Document::Ptr doc = Document::create("shadowedNames_2"); + doc->setUtf8Source(src); + doc->parse(); + doc->check(); + + QVERIFY(doc->diagnosticMessages().isEmpty()); + QCOMPARE(doc->globalSymbolCount(), 5U); + + Snapshot snapshot; + snapshot.insert(doc); + + Class *c = doc->globalSymbolAt(1)->asClass(); + QVERIFY(c); + QCOMPARE(c->name()->identifier()->chars(), "X"); + QCOMPARE(c->memberCount(), 1U); + Declaration *d = c->memberAt(0)->asDeclaration(); + QVERIFY(d); + QCOMPARE(d->name()->identifier()->chars(), "a"); + + FindUsages findUsages(src, doc, snapshot); + findUsages(d); + QCOMPARE(findUsages.usages().size(), 3); +} + #if 0 @interface Clazz {} +(void)method:(int)arg; @end @implementation Clazz +(void)method:(int)arg {