CppEditor: Fix "add definition" quickfix insertion string

... for the edge case of the insertion location being preceded by a
function whose body is a try-catch clause.

Fixes: QTCREATORBUG-14661
Change-Id: Icc7d5283ead81d644231479317214a8cc177493d
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2021-01-28 10:27:12 +01:00
parent ad09faab4e
commit 667d50e1bc
3 changed files with 49 additions and 0 deletions

View File

@@ -3111,6 +3111,15 @@ public:
// make target lookup context
Document::Ptr targetDoc = targetFile->cppDocument();
Scope *targetScope = targetDoc->scopeAt(loc.line(), loc.column());
// Correct scope in case of a function try-block. See QTCREATORBUG-14661.
if (targetScope && targetScope->asBlock()) {
if (Class * const enclosingClass = targetScope->enclosingClass())
targetScope = enclosingClass;
else
targetScope = targetScope->enclosingNamespace();
}
LookupContext targetContext(targetDoc, op->snapshot());
ClassOrNamespace *targetCoN = targetContext.lookupType(targetScope);
if (!targetCoN)