diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp
index f89d5df105784a95a9e351b5a5d1b551a604b059..88ca3b755879be21d999505a201b45cdace14b4e 100644
--- a/src/plugins/cpptools/cppcodecompletion.cpp
+++ b/src/plugins/cpptools/cppcodecompletion.cpp
@@ -445,7 +445,6 @@ CppCodeCompletion::CppCodeCompletion(CppModelManager *manager)
       m_completionOperator(T_EOF_SYMBOL),
       m_objcEnabled(true)
 {
-    m_sorted = false;
 }
 
 QIcon CppCodeCompletion::iconForSymbol(Symbol *symbol) const
@@ -655,7 +654,14 @@ bool CppCodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor)
 
 int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
 {
-    m_sorted = false;
+    int index = startCompletionHelper(editor);
+    if (index != -1)
+        qStableSort(m_completions.begin(), m_completions.end(), completionItemLessThan);
+    return index;
+}
+
+int CppCodeCompletion::startCompletionHelper(TextEditor::ITextEditable *editor)
+{
     TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor *>(editor->widget());
     if (! edit)
         return -1;
@@ -1592,11 +1598,6 @@ QList<TextEditor::CompletionItem> CppCodeCompletion::getCompletions()
 
     completions(&completionItems);
 
-    if (! m_sorted) {
-        qStableSort(completionItems.begin(), completionItems.end(), completionItemLessThan);
-        m_sorted = true;
-    }
-
     // Remove duplicates
     QString lastKey;
     QList<TextEditor::CompletionItem> uniquelist;
@@ -1741,7 +1742,6 @@ bool CppCodeCompletion::partiallyComplete(const QList<TextEditor::CompletionItem
 
 void CppCodeCompletion::cleanup()
 {
-    m_sorted = false;
     m_completions.clear();
 
     // Set empty map in order to avoid referencing old versions of the documents
diff --git a/src/plugins/cpptools/cppcodecompletion.h b/src/plugins/cpptools/cppcodecompletion.h
index 432f1f298ab9560976ff621ee14e92d13c31d224..f7d1667f761ca2dd916abba3b26dcbf04059ea1a 100644
--- a/src/plugins/cpptools/cppcodecompletion.h
+++ b/src/plugins/cpptools/cppcodecompletion.h
@@ -122,6 +122,8 @@ private:
 
     int findStartOfName(int pos = -1) const;
 
+    int startCompletionHelper(TextEditor::ITextEditable *editor);
+
     int startCompletionInternal(TextEditor::BaseTextEditor *edit,
                                 const QString fileName,
                                 unsigned line, unsigned column,
@@ -147,7 +149,6 @@ private:
     QPointer<FunctionArgumentWidget> m_functionArgumentWidget;
 
     QList<TextEditor::CompletionItem> m_completions;
-    bool m_sorted;
 };
 
 } // namespace Internal