From 8b8a5db129bb5c30e2626c80228e8e2f5b1db1b9 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 19 Apr 2013 14:04:13 +0200 Subject: [PATCH] Revert "C++: fix support for typedef of templated typedefs" Infinite recursion in the lookup of: struct common_type { public: typedef typename common_type::type, V>::type type; }; This reverts commit 9a56ce4e85bec81c521258f44e9076d0bc9cce92 Change-Id: I675fe39018789cd04127d105eb983d2cb7798ca5 Reviewed-by: Erik Verbruggen --- src/libs/cplusplus/LookupContext.cpp | 55 +-------------- src/libs/cplusplus/LookupContext.h | 3 - src/libs/cplusplus/ResolveExpression.cpp | 11 +-- src/plugins/cpptools/cppcompletion_test.cpp | 74 --------------------- src/plugins/cpptools/cpptoolsplugin.h | 2 - 5 files changed, 5 insertions(+), 140 deletions(-) diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp index 6df4b43cf36..dde50df687f 100644 --- a/src/libs/cplusplus/LookupContext.cpp +++ b/src/libs/cplusplus/LookupContext.cpp @@ -719,43 +719,10 @@ ClassOrNamespace *ClassOrNamespace::lookupType_helper(const Name *name, if (name->isNameId() || name->isTemplateNameId() || name->isAnonymousNameId()) { flush(); - if (name->isTemplateNameId()) { - // if it is a base specialization, the 'name' could be an instantiation - QMap::iterator it - = _instantiations.find(name->asTemplateNameId()); - if (it != _instantiations.end()) - return it.value(); - } - foreach (Symbol *s, symbols()) { if (Class *klass = s->asClass()) { if (klass->identifier() && klass->identifier()->isEqualTo(name->identifier())) return this; - - // it can be a typedef - const unsigned memberClassCount = klass->memberCount(); - for (unsigned i = 0; i < memberClassCount; ++i) { - Symbol *memberClassAsSymbol = klass->memberAt(i); - if (Declaration *declaration = memberClassAsSymbol->asDeclaration()) { - if (declaration->isTypedef() - && name->identifier()->isEqualTo(declaration->name()->identifier - ())) { - if (NamedType *namedType = declaration->type()->asNamedType()) { - QSet innerProcessed; - const Name *namedTypeName = namedType->name(); - const QualifiedNameId *q = namedTypeName->asQualifiedNameId(); - if (q && name->isEqualTo(q->base()) - && name->isEqualTo(q->name())) { - return lookupType_helper_inParent(name, &innerProcessed, - searchInEnclosingScope, - origin); - } - return lookupType_helper(namedTypeName, &innerProcessed, - true, origin); - } - } - } - } } } @@ -779,9 +746,6 @@ ClassOrNamespace *ClassOrNamespace::lookupType_helper(const Name *name, } foreach (ClassOrNamespace *u, usings()) { - // usings are not instantiated for templates - if (_templateId && u->_templateId) - continue; if (ClassOrNamespace *r = u->lookupType_helper(name, processed, /*searchInEnclosingScope =*/ false, @@ -790,21 +754,8 @@ ClassOrNamespace *ClassOrNamespace::lookupType_helper(const Name *name, } } - return lookupType_helper_inParent(name, processed, searchInEnclosingScope, origin); - } - - return 0; -} - -ClassOrNamespace *ClassOrNamespace::lookupType_helper_inParent(const Name *name, QSet *processed, - bool searchInEnclosingScope, ClassOrNamespace *origin) -{ - if (_parent && searchInEnclosingScope) { - // for templates _parent is a base specialization, - // so we should take here rather _parent of this base specialization - ClassOrNamespace *parent = _templateId ? _parent->_parent : _parent; - if (parent) - return parent->lookupType_helper(name, processed, searchInEnclosingScope, origin); + if (_parent && searchInEnclosingScope) + return _parent->lookupType_helper(name, processed, searchInEnclosingScope, origin); } return 0; @@ -1008,7 +959,7 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac oo.showReturnTypes = true; oo.showTemplateParameters = true; qDebug()<<"cloned"<type()); - if (Class *klass = clone->asClass()) { + if (Class *klass = s->asClass()) { const unsigned klassMemberCount = klass->memberCount(); for (unsigned i = 0; i < klassMemberCount; ++i){ Symbol *klassMemberAsSymbol = klass->memberAt(i); diff --git a/src/libs/cplusplus/LookupContext.h b/src/libs/cplusplus/LookupContext.h index d1e64cdd87f..3dbe525766a 100644 --- a/src/libs/cplusplus/LookupContext.h +++ b/src/libs/cplusplus/LookupContext.h @@ -111,9 +111,6 @@ private: ClassOrNamespace *lookupType_helper(const Name *name, QSet *processed, bool searchInEnclosingScope, ClassOrNamespace *origin); - ClassOrNamespace *lookupType_helper_inParent(const Name *name, QSet *processed, - bool searchInEnclosingScope, ClassOrNamespace *origin); - ClassOrNamespace *nestedType(const Name *name, ClassOrNamespace *origin); void instantiateNestedClasses(ClassOrNamespace *enclosingTemplateClass, diff --git a/src/libs/cplusplus/ResolveExpression.cpp b/src/libs/cplusplus/ResolveExpression.cpp index 8a72fc1fc2a..029bcee00d4 100644 --- a/src/libs/cplusplus/ResolveExpression.cpp +++ b/src/libs/cplusplus/ResolveExpression.cpp @@ -690,15 +690,8 @@ bool ResolveExpression::visit(CallAST *ast) } } else if (Function *funTy = ty->asFunctionType()) { - if (maybeValidPrototype(funTy, actualArgumentCount)) { - LookupItem item; - item.setType(funTy->returnType().simplified()); - item.setScope(scope); - // we have to remember a binding because it can be a template instantiation - item.setBinding(result.binding()); - - _results.append(item); - } + if (maybeValidPrototype(funTy, actualArgumentCount)) + addResult(funTy->returnType().simplified(), scope); } else if (Class *classTy = ty->asClassType()) { // Constructor call diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp index 70a5469b123..b8ee95f7c04 100644 --- a/src/plugins/cpptools/cppcompletion_test.cpp +++ b/src/plugins/cpptools/cppcompletion_test.cpp @@ -1882,77 +1882,3 @@ void CppToolsPlugin::test_completion_QTCREATORBUG9098() QVERIFY(completions.contains(QLatin1String("c"))); QVERIFY(completions.contains(QLatin1String("B"))); } - -void CppToolsPlugin::test_completion_typedef_of_templated_typedef_QTCREATORBUG8375() -{ - TestData data; - data.srcText = - "struct Foo\n" - "{ void bar(); };\n" - "struct A\n" - "{ typedef Foo AFoo; };\n" - "template \n" - "struct B\n" - "{ typedef typename T::AFoo BFoo; };\n" - "struct C : public B\n" - "{\n" - " void test()\n" - " {\n" - " BFoo foo;\n" - " @\n" - " // padding so we get the scope right\n" - " }\n" - "};\n" - ; - setup(&data); - - Utils::ChangeSet change; - QString txt = QLatin1String("foo."); - change.insert(data.pos, txt); - QTextCursor cursor(data.doc); - change.apply(&cursor); - data.pos += txt.length(); - - QStringList completions = getCompletions(data); - - QCOMPARE(completions.size(), 2); - QVERIFY(completions.contains(QLatin1String("Foo"))); - QVERIFY(completions.contains(QLatin1String("bar"))); -} - -void CppToolsPlugin::test_completion_typedef_with_the_same_base_name_and_new_type_name() -{ - TestData data; - data.srcText = - "namespace A\n" - "{\n" - "struct A { int aa; };\n" - "}\n" - "struct S\n" - "{\n" - " typedef A::A A;\n" - " A a;\n" - "};\n" - "void fun()\n" - "{\n" - " S s;\n" - " @\n" - " // padding so we get the scope right\n" - "};\n" - ; - setup(&data); - - Utils::ChangeSet change; - QString txt = QLatin1String("s.a."); - change.insert(data.pos, txt); - QTextCursor cursor(data.doc); - change.apply(&cursor); - data.pos += txt.length(); - - QStringList completions = getCompletions(data); - - QCOMPARE(completions.size(), 2); - QVERIFY(completions.contains(QLatin1String("A"))); - QVERIFY(completions.contains(QLatin1String("aa"))); -} - diff --git a/src/plugins/cpptools/cpptoolsplugin.h b/src/plugins/cpptools/cpptoolsplugin.h index 3bfb64688be..10975a53013 100644 --- a/src/plugins/cpptools/cpptoolsplugin.h +++ b/src/plugins/cpptools/cpptoolsplugin.h @@ -124,8 +124,6 @@ private slots: void test_completion_typedef_using_templates2(); void test_completion_namespace_alias_with_many_namespace_declarations(); void test_completion_QTCREATORBUG9098(); - void test_completion_typedef_of_templated_typedef_QTCREATORBUG8375(); - void test_completion_typedef_with_the_same_base_name_and_new_type_name(); void test_format_pointerdeclaration_in_simpledeclarations(); void test_format_pointerdeclaration_in_simpledeclarations_data();