summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2020-05-27 11:29:34 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2020-05-28 09:33:55 +0000
commit3563c457a55fc80384957a41eee0d9ebcf3cc125 (patch)
tree8f881b066319c5e1c4a8abd67fae725be5e54db1
parent24777becb91357a8dbade3b1744622d23c2d0da4 (diff)
downloadqt-creator-3563c457a55fc80384957a41eee0d9ebcf3cc125.tar.gz
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>
-rw-r--r--src/plugins/cppeditor/cppfunctiondecldeflink.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
index 7368ecb416..73e28c89e1 100644
--- a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
+++ b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
@@ -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) {
// move all change operations to have the right start offset
const int moveAmount = targetOffset - targetFile->startOf(targetDeclaration);