C++: fix matching type with using from other namespace

example code:
struct S { int s; };

namespace std
{
    template <typename T>
    struct shared_ptr
    {
        T* operator->();
    };
}

namespace NS
{
    using std::shared_ptr;
}

int main()
{
    NS::shared_ptr<S> p;// for this shared_ptr
    return 0;
}

Fixes:
* find usages
* follow symbol
* highlighting
* marking

Task-number: QTCREATORBUG-7978
Change-Id: I28994c960b87ddd400e1d7b860fca6c6683bbb5a
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
Przemyslaw Gorszkowski
2013-08-11 22:10:26 +02:00
committed by Erik Verbruggen
parent 9de44134c0
commit 3256b7b2ef
4 changed files with 89 additions and 3 deletions

View File

@@ -246,12 +246,13 @@ QList<LookupItem> LookupContext::lookupByUsing(const Name *name, Scope *scope) c
{
QList<LookupItem> candidates;
// if it is a nameId there can be a using declaration for it
if (name->isNameId()) {
if (name->isNameId() || name->isTemplateNameId()) {
for (unsigned i = 0, count = scope->memberCount(); i < count; ++i) {
if (UsingDeclaration *u = scope->memberAt(i)->asUsingDeclaration()) {
if (const Name *usingDeclarationName = u->name()) {
if (const QualifiedNameId *q = usingDeclarationName->asQualifiedNameId()) {
if (q->name() && q->name()->isEqualTo(name)) {
if (q->name() && q->identifier() && name->identifier()
&& q->name()->identifier()->isEqualTo(name->identifier())) {
candidates = bindings()->globalNamespace()->find(q);
// if it is not a global scope(scope of scope is not equal 0)
@@ -267,6 +268,10 @@ QList<LookupItem> LookupContext::lookupByUsing(const Name *name, Scope *scope) c
}
}
}
} else if (const QualifiedNameId *q = name->asQualifiedNameId()) {
ClassOrNamespace *base = lookupType(q->base(), scope);
if (base && base->symbols().size() > 0 && base->symbols().first()->asScope())
return lookupByUsing(q->name(), base->symbols().first()->asScope());
}
return candidates;
}