diff --git a/src/libs/cplusplus/CppDocument.cpp b/src/libs/cplusplus/CppDocument.cpp
index bbf3eac045e684a963b73aeb0c46501ccb8c0342..94832cc1420f8606d49e51b07bfe0e5b888acf2f 100644
--- a/src/libs/cplusplus/CppDocument.cpp
+++ b/src/libs/cplusplus/CppDocument.cpp
@@ -94,7 +94,7 @@ protected:
                 unsigned endLine, endColumn;
                 _unit->getPosition(symbol->endOffset(), &endLine, &endColumn);
 
-                if (_line < endLine || (_line == endLine && _column < endColumn))
+                if (_line < endLine || (_line == endLine && _column <= endColumn))
                     _scope = scope;
             }
         }
@@ -148,6 +148,7 @@ protected:
     { return process(symbol); }
 };
 
+
 class DocumentDiagnosticClient : public DiagnosticClient
 {
     enum { MAX_MESSAGE_COUNT = 10 };
diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp
index d6c23a700cdac2ce0ef42758805292df96f674e2..f4794d4886db7b2d5b7ec198b9bb6e8547da642a 100644
--- a/src/plugins/cpptools/cppcodecompletion.cpp
+++ b/src/plugins/cpptools/cppcodecompletion.cpp
@@ -809,10 +809,6 @@ int CppCodeCompletion::startCompletionHelper(TextEditor::ITextEditable *editor)
     Core::IFile *file = editor->file();
     QString fileName = file->fileName();
 
-    int line = 0, column = 0;
-    edit->convertPosition(editor->position(), &line, &column);
-    // qDebug() << "line:" << line << "column:" << column;
-
     if (m_completionOperator == T_DOXY_COMMENT) {
         for (int i = 1; i < T_DOXY_LAST_TAG; ++i) {
             TextEditor::CompletionItem item(this);
@@ -860,10 +856,12 @@ int CppCodeCompletion::startCompletionHelper(TextEditor::ITextEditable *editor)
     }
 
     QString expression;
+    int startOfExpression = editor->position();
     tc.setPosition(endOfExpression);
 
     if (m_completionOperator) {
         expression = expressionUnderCursor(tc);
+        startOfExpression = endOfExpression - expression.length();
 
         if (m_completionOperator == T_LPAREN) {
             if (expression.endsWith(QLatin1String("SIGNAL")))
@@ -877,11 +875,18 @@ int CppCodeCompletion::startCompletionHelper(TextEditor::ITextEditable *editor)
                 expression.clear();
                 m_completionOperator = T_EOF_SYMBOL;
                 m_startPosition = startOfName;
+                startOfExpression = editor->position();
             }
         }
+    } else if (expression.isEmpty()) {
+        while (startOfExpression > 0 && editor->characterAt(startOfExpression).isSpace())
+            --startOfExpression;
     }
 
-    //qDebug() << "***** expression:" << expression;
+    int line = 0, column = 0;
+    edit->convertPosition(startOfExpression, &line, &column);
+//    qDebug() << "***** line:" << line << "column:" << column;
+//    qDebug() << "***** expression:" << expression;
     return startCompletionInternal(edit, fileName, line, column, expression, endOfExpression);
 }
 
@@ -1168,26 +1173,8 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<LookupItem> &r
 
         // find a scope that encloses the current location, starting from the lastVisibileSymbol
         // and moving outwards
-        Scope *sc = 0;
-        if (typeOfExpression.scope())
-            sc = typeOfExpression.scope();
-        else if (context.thisDocument())
-            sc = context.thisDocument()->globalSymbols();
-
-        while (sc && sc->enclosingScope()) {
-            unsigned startLine, startColumn;
-            context.thisDocument()->translationUnit()->getPosition(sc->owner()->startOffset(), &startLine, &startColumn);
-            unsigned endLine, endColumn;
-            context.thisDocument()->translationUnit()->getPosition(sc->owner()->endOffset(), &endLine, &endColumn);
-
-            if (startLine <= line && line <= endLine) {
-                if ((startLine != line || startColumn <= column)
-                    && (endLine != line || column <= endColumn))
-                    break;
-            }
 
-            sc = sc->enclosingScope();
-        }
+        Scope *sc = context.thisDocument()->scopeAt(line, column);
 
         if (sc && (sc->isClassScope() || sc->isNamespaceScope())) {
             // It may still be a function call. If the whole line parses as a function