From 3563c457a55fc80384957a41eee0d9ebcf3cc125 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 27 May 2020 11:29:34 +0200 Subject: 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 --- src/plugins/cppeditor/cppfunctiondecldeflink.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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); -- cgit v1.2.1