diff --git a/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp b/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp index ac2747cad71..11a3a70be09 100644 --- a/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp +++ b/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp @@ -417,17 +417,18 @@ bool maybeAppendArgumentOrParameterList(QString *expression, const QTextCursor & bool isCursorOnTrailingReturnType(const QList &astPath) { - for (auto it = astPath.cend() - 1, begin = astPath.cbegin(); it >= begin; --it) { + if (astPath.size() < 3) + return false; + for (auto it = astPath.cend() - 3, begin = astPath.cbegin(); it >= begin; --it) { + if (!(*it)->asTrailingReturnType()) + continue; const auto nextIt = it + 1; const auto nextNextIt = nextIt + 1; - if (nextNextIt != astPath.cend() && (*it)->asTrailingReturnType()) { - return (*nextIt)->asNamedTypeSpecifier() - && ((*nextNextIt)->asSimpleName() - || (*nextNextIt)->asQualifiedName() - || (*nextNextIt)->asTemplateId()); - } + return (*nextIt)->asNamedTypeSpecifier() + && ((*nextNextIt)->asSimpleName() + || (*nextNextIt)->asQualifiedName() + || (*nextNextIt)->asTemplateId()); } - return false; }