diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp
index 00bb4d596910c41ba3aa23cbf74338707f362976..7418b8e8087539a1be3b4be0e8bb0eb0cc9418c4 100644
--- a/src/libs/cplusplus/LookupContext.cpp
+++ b/src/libs/cplusplus/LookupContext.cpp
@@ -69,9 +69,10 @@ bool ClassOrNamespace::CompareName::operator()(const Name *name, const Name *oth
 {
     Q_ASSERT(name != 0);
     Q_ASSERT(other != 0);
+
     const Identifier *id = name->identifier();
     const Identifier *otherId = other->identifier();
-    return std::lexicographical_compare(id->begin(), id->end(), otherId->begin(), otherId->end());
+    return strcmp(id->chars(), otherId->chars()) < 0;
 }
 
 /////////////////////////////////////////////////////////////////////
@@ -266,6 +267,11 @@ ClassOrNamespace::ClassOrNamespace(CreateBindings *factory, ClassOrNamespace *pa
 {
 }
 
+ClassOrNamespace *ClassOrNamespace::parent() const
+{
+    return _parent;
+}
+
 QList<ClassOrNamespace *> ClassOrNamespace::usings() const
 {
     const_cast<ClassOrNamespace *>(this)->flush();
@@ -401,7 +407,7 @@ void CreateBindings::lookup_helper(const Name *name, Scope *scope,
 #if 0
             if (templateId && (s->isDeclaration() || s->isFunction())) {
 
-                FullySpecifiedType ty = GenTemplateInstance::instantiate(templateId, s, control);
+                FullySpecifiedType ty = GenTemplateInstance::instantiate(templateId, s, _control);
 
                 Overview oo;
                 oo.setShowFunctionSignatures(true);
@@ -412,19 +418,15 @@ void CreateBindings::lookup_helper(const Name *name, Scope *scope,
 
                 if (Declaration *decl = s->asDeclaration()) {
                     qDebug() << "instantiate declaration";
-                    qDebug() << "is typedef:" << ty.isTypedef() << s->isTypedef() << s->type().isTypedef();
-                    Declaration *d = control->newDeclaration(0, 0);
-                    d->setStorage(decl->storage());
-                    d->setName(decl->name());
+                    Declaration *d = _control->newDeclaration(0, 0);
+                    d->copy(decl);
                     d->setType(ty);
-                    d->setScope(decl->scope());
                     result->append(d);
                     continue;
                 } else if (Function *fun = s->asFunction()) {
                     qDebug() << "instantiate function";
                     Function *d = ty->asFunctionType();
-                    d->setStorage(fun->storage());
-                    d->setScope(fun->scope());
+                    d->copy(fun);
                     result->append(d);
                     continue;
                 }
diff --git a/src/libs/cplusplus/LookupContext.h b/src/libs/cplusplus/LookupContext.h
index 20188c6d21d3ae6ab7cdc61fa2e625b3617f4a0f..4a9bb9432c11d4211cec27a65749164830451cd3 100644
--- a/src/libs/cplusplus/LookupContext.h
+++ b/src/libs/cplusplus/LookupContext.h
@@ -48,6 +48,7 @@ class CPLUSPLUS_EXPORT ClassOrNamespace
 public:
     ClassOrNamespace(CreateBindings *factory, ClassOrNamespace *parent);
 
+    ClassOrNamespace *parent() const;
     QList<ClassOrNamespace *> usings() const;
     QList<Enum *> enums() const;
     QList<Symbol *> symbols() const;
diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp
index 198ff12ccad1a29d3519d489455b1b02c24c0176..4edf10962465b6590cc8775f621eec23a5e3c5af 100644
--- a/src/plugins/cpptools/cppcodecompletion.cpp
+++ b/src/plugins/cpptools/cppcodecompletion.cpp
@@ -1115,7 +1115,7 @@ bool CppCodeCompletion::completeMember(const QList<LookupItem> &baseResults,
             classObjectCandidates.append(klass);
 
         else if (NamedType *namedTy = ty->asNamedType()) {
-            if (ClassOrNamespace *b = context.classOrNamespace(namedTy->name(), r.lastVisibleSymbol()->scope())) {
+            if (ClassOrNamespace *b = context.classOrNamespace(namedTy->name(), r.lastVisibleSymbol())) {
                 classOrNamespace = b;
                 break;
 
@@ -1342,22 +1342,6 @@ void CppCodeCompletion::completeNamespace(ClassOrNamespace *b, const LookupConte
     }
 }
 
-void CppCodeCompletion::completeNamespace(const QList<Symbol *> &candidates,
-                                          const DeprecatedLookupContext &deprecatedContext)
-{
-    if (candidates.isEmpty())
-        return;
-
-    else if (Namespace *ns = candidates.first()->asNamespace()) {
-        LookupContext context(deprecatedContext.expressionDocument(),
-                              deprecatedContext.thisDocument(),
-                              deprecatedContext.snapshot());
-
-        if (ClassOrNamespace *binding = context.classOrNamespace(ns))
-            completeNamespace(binding, context);
-    }
-}
-
 void CppCodeCompletion::completeClass(ClassOrNamespace *b, const LookupContext &, bool staticLookup)
 {
     QSet<ClassOrNamespace *> bindingsVisited;
@@ -1405,23 +1389,6 @@ void CppCodeCompletion::completeClass(ClassOrNamespace *b, const LookupContext &
     }
 }
 
-void CppCodeCompletion::completeClass(const QList<Symbol *> &candidates,
-                                      const DeprecatedLookupContext &deprecatedContext,
-                                      bool staticLookup)
-{
-    if (candidates.isEmpty())
-        return;
-
-    else if (Symbol *klass = candidates.first()) {
-        LookupContext context(deprecatedContext.expressionDocument(),
-                              deprecatedContext.thisDocument(),
-                              deprecatedContext.snapshot());
-
-        if (ClassOrNamespace *binding = context.classOrNamespace(klass))
-            completeClass(binding, context, staticLookup);
-    }
-}
-
 bool CppCodeCompletion::completeQtMethod(const QList<LookupItem> &results,
                                          const LookupContext &newContext,
                                          bool wantSignals)
diff --git a/src/plugins/cpptools/cppcodecompletion.h b/src/plugins/cpptools/cppcodecompletion.h
index a91956ce8a80ba11ccbbb0c35758c66dc6e8f233..c2938a6726fe1e5087e79347292389a3961e5abd 100644
--- a/src/plugins/cpptools/cppcodecompletion.h
+++ b/src/plugins/cpptools/cppcodecompletion.h
@@ -126,17 +126,10 @@ private:
     void completeNamespace(CPlusPlus::ClassOrNamespace *binding,
                            const CPlusPlus::LookupContext &context);
 
-    void completeNamespace(const QList<CPlusPlus::Symbol *> &candidates,
-                           const CPlusPlus::DeprecatedLookupContext &context);
-
     void completeClass(CPlusPlus::ClassOrNamespace *b,
                        const CPlusPlus::LookupContext &context,
                        bool staticLookup = true);
 
-    void completeClass(const QList<CPlusPlus::Symbol *> &candidates,
-                       const CPlusPlus::DeprecatedLookupContext &context,
-                       bool staticLookup = true);
-
     bool completeConstructors(CPlusPlus::Class *klass);
 
     bool completeQtMethod(const QList<CPlusPlus::LookupItem> &results,
diff --git a/src/shared/cplusplus/Symbol.cpp b/src/shared/cplusplus/Symbol.cpp
index 93725ee22465845d5e86f0fa28ea557a7ec82d4b..8572f191dcb67a03c039bca617119bdf393f6d8a 100644
--- a/src/shared/cplusplus/Symbol.cpp
+++ b/src/shared/cplusplus/Symbol.cpp
@@ -161,7 +161,7 @@ private:
 };
 
 Symbol::Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
-    : _control(translationUnit->control()),
+    : _control(0),
       _sourceLocation(sourceLocation),
       _sourceOffset(0),
       _startOffset(0),
@@ -175,7 +175,11 @@ Symbol::Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, const
       _next(0),
       _isGenerated(false)
 {
-    setSourceLocation(sourceLocation);
+    if (translationUnit) {
+        _control = translationUnit->control();
+        setSourceLocation(sourceLocation);
+    }
+
     setName(name);
 }
 
@@ -504,3 +508,22 @@ bool Symbol::isObjCMethod() const
 
 bool Symbol::isObjCPropertyDeclaration() const
 { return asObjCPropertyDeclaration() != 0; }
+
+void Symbol::copy(Symbol *other)
+{
+    _control = other->_control;
+    _sourceLocation = other->_sourceLocation;
+    _sourceOffset = other->_sourceOffset;
+    _startOffset = other->_startOffset;
+    _endOffset = other->_endOffset;
+    _name = other->_name;
+    _hashCode = other->_hashCode;
+    _storage = other->_storage;
+    _visibility = other->_visibility;
+    _scope = other->_scope;
+    _index = other->_index;
+    _next = other->_next;
+
+    _isGenerated = other->_isGenerated;
+    _isDeprecated = other->_isDeprecated;
+}
diff --git a/src/shared/cplusplus/Symbol.h b/src/shared/cplusplus/Symbol.h
index 628261b4b9a63c7485d679d8cd7cbe44976cce5c..ab762f63811e9c6ac13646904f69036c8309d1f0 100644
--- a/src/shared/cplusplus/Symbol.h
+++ b/src/shared/cplusplus/Symbol.h
@@ -317,6 +317,8 @@ public:
     void visitSymbol(SymbolVisitor *visitor);
     static void visitSymbol(Symbol *symbol, SymbolVisitor *visitor);
 
+    virtual void copy(Symbol *other);
+
 protected:
     virtual void visitSymbol0(SymbolVisitor *visitor) = 0;