summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppcodecompletion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/cpptools/cppcodecompletion.cpp')
-rw-r--r--src/plugins/cpptools/cppcodecompletion.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp
index 6dbbe4ad86..b62c421658 100644
--- a/src/plugins/cpptools/cppcodecompletion.cpp
+++ b/src/plugins/cpptools/cppcodecompletion.cpp
@@ -1019,8 +1019,13 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<TypeOfExpressi
// find a scope that encloses the current location, starting from the lastVisibileSymbol
// and moving outwards
- Scope *sc = context.symbol()->scope();
- while (sc->enclosingScope()) {
+ Scope *sc = 0;
+ if (context.symbol())
+ sc = context.symbol()->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;
@@ -1034,7 +1039,7 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<TypeOfExpressi
sc = sc->enclosingScope();
}
- if (sc->isClassScope() || sc->isNamespaceScope())
+ if (sc && (sc->isClassScope() || sc->isNamespaceScope()))
{
// It may still be a function call. If the whole line parses as a function
// declaration, we should be certain that it isn't.