From 6b4db9e674a3a29a0ba2536cc9f87bf2ced3be4c Mon Sep 17 00:00:00 2001
From: Roberto Raggi <roberto.raggi@nokia.com>
Date: Tue, 29 Sep 2009 12:46:42 +0200
Subject: [PATCH] Handle ctor-initializers in the LookupContext.

---
 src/libs/cplusplus/LookupContext.cpp       | 7 ++++++-
 src/plugins/cpptools/cppcodecompletion.cpp | 9 ++++-----
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp
index f0bbb4ffca8..a736b3dd7af 100644
--- a/src/libs/cplusplus/LookupContext.cpp
+++ b/src/libs/cplusplus/LookupContext.cpp
@@ -276,7 +276,12 @@ QList<Scope *> LookupContext::buildVisibleScopes()
     QList<Scope *> scopes;
 
     if (_symbol) {
-        for (Scope *scope = _symbol->scope(); scope; scope = scope->enclosingScope()) {
+        Scope *scope = _symbol->scope();
+
+        if (Function *fun = _symbol->asFunction())
+            scope = fun->members(); // handle ctor initializers.
+
+        for (; scope; scope = scope->enclosingScope()) {
             if (scope == _thisDocument->globalSymbols())
                 break;
 
diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp
index 63a4d4c6cc1..bc1d1d4ad72 100644
--- a/src/plugins/cpptools/cppcodecompletion.cpp
+++ b/src/plugins/cpptools/cppcodecompletion.cpp
@@ -817,11 +817,10 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
     const Snapshot snapshot = m_manager->snapshot();
 
     if (Document::Ptr thisDocument = snapshot.value(fileName)) {
-        Symbol *symbol = thisDocument->findSymbolAt(line, column);
-
+        Symbol *lastVisibleSymbol = thisDocument->findSymbolAt(line, column);
         typeOfExpression.setSnapshot(m_manager->snapshot());
 
-        QList<TypeOfExpression::Result> resolvedTypes = typeOfExpression(expression, thisDocument, symbol,
+        QList<TypeOfExpression::Result> resolvedTypes = typeOfExpression(expression, thisDocument, lastVisibleSymbol,
                                                                          TypeOfExpression::Preprocess);
         LookupContext context = typeOfExpression.lookupContext();
 
@@ -847,7 +846,7 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
                                         m_completionOperator == T_SLOT)) {
             // Apply signal/slot completion on 'this'
             expression = QLatin1String("this");
-            resolvedTypes = typeOfExpression(expression, thisDocument, symbol);
+            resolvedTypes = typeOfExpression(expression, thisDocument, lastVisibleSymbol);
             context = typeOfExpression.lookupContext();
         }
 
@@ -883,7 +882,7 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
 
             // Resolve the type of this expression
             QList<TypeOfExpression::Result> results =
-                    typeOfExpression(baseExpression, thisDocument, symbol, TypeOfExpression::Preprocess);
+                    typeOfExpression(baseExpression, thisDocument, lastVisibleSymbol, TypeOfExpression::Preprocess);
 
             // If it's a class, add completions for the constructors
             foreach (const TypeOfExpression::Result &result, results) {
-- 
GitLab