CppEditor: Detect changes in a function's exception specification

... so that the light bulb will pop up and let the user change the
associated declaration or definition.

Fixes: QTCREATORBUG-23895
Change-Id: I71032d81782b6d0bef929ecfa837eda2f5caec09
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
Christian Kandeler
2020-05-27 11:29:34 +02:00
parent 24777becb9
commit 3563c457a5

View File

@@ -939,6 +939,30 @@ ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targetOffse
} }
} }
// sync noexcept/throw()
const QString exceptionSpecTarget = targetFunction->exceptionSpecification()
? QString::fromUtf8(targetFunction->exceptionSpecification()->chars()) : QString();
const QString exceptionSpecNew = newFunction->exceptionSpecification()
? QString::fromUtf8(newFunction->exceptionSpecification()->chars()) : QString();
if (exceptionSpecTarget != exceptionSpecNew) {
if (!exceptionSpecTarget.isEmpty() && !exceptionSpecNew.isEmpty()) {
changes.replace(targetFile->range(targetFunctionDeclarator->exception_specification),
exceptionSpecNew);
} else if (exceptionSpecTarget.isEmpty()) {
int previousToken = targetFunctionDeclarator->ref_qualifier_token;
if (!previousToken) {
const SpecifierListAST *cvList = targetFunctionDeclarator->cv_qualifier_list;
if (cvList && cvList->lastValue()->asSimpleSpecifier())
previousToken = cvList->lastValue()->asSimpleSpecifier()->specifier_token;
}
if (!previousToken)
previousToken = targetFunctionDeclarator->rparen_token;
changes.insert(targetFile->endOf(previousToken), ' ' + exceptionSpecNew);
} else if (!exceptionSpecTarget.isEmpty()) {
changes.remove(targetFile->range(targetFunctionDeclarator->exception_specification));
}
}
if (targetOffset != -1) { if (targetOffset != -1) {
// move all change operations to have the right start offset // move all change operations to have the right start offset
const int moveAmount = targetOffset - targetFile->startOf(targetDeclaration); const int moveAmount = targetOffset - targetFile->startOf(targetDeclaration);