Fixed possible crash when completing top-level declarations.

This commit is contained in:
Roberto Raggi
2009-10-20 17:17:11 +02:00
parent 7c68acbd3f
commit 1006be240d

View File

@@ -1019,8 +1019,13 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<TypeOfExpressi
// find a scope that encloses the current location, starting from the lastVisibileSymbol // find a scope that encloses the current location, starting from the lastVisibileSymbol
// and moving outwards // and moving outwards
Scope *sc = context.symbol()->scope(); Scope *sc = 0;
while (sc->enclosingScope()) { if (context.symbol())
sc = context.symbol()->scope();
else if (context.thisDocument())
sc = context.thisDocument()->globalSymbols();
while (sc && sc->enclosingScope()) {
unsigned startLine, startColumn; unsigned startLine, startColumn;
context.thisDocument()->translationUnit()->getPosition(sc->owner()->startOffset(), &startLine, &startColumn); context.thisDocument()->translationUnit()->getPosition(sc->owner()->startOffset(), &startLine, &startColumn);
unsigned endLine, endColumn; unsigned endLine, endColumn;
@@ -1034,7 +1039,7 @@ bool CppCodeCompletion::completeConstructorOrFunction(const QList<TypeOfExpressi
sc = sc->enclosingScope(); 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 // It may still be a function call. If the whole line parses as a function
// declaration, we should be certain that it isn't. // declaration, we should be certain that it isn't.