aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/cppeditor/cppfunctiondecldeflink.cpp')
-rw-r--r--src/plugins/cppeditor/cppfunctiondecldeflink.cpp50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
index 7368ecb416..d0494f8b0f 100644
--- a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
+++ b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
@@ -437,6 +437,7 @@ static bool canReplaceSpecifier(TranslationUnit *translationUnit, SpecifierAST *
case T_AUTO:
case T___TYPEOF__:
case T___ATTRIBUTE__:
+ case T___DECLSPEC:
return true;
default:
return false;
@@ -572,7 +573,7 @@ ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targetOffse
// abort if the name of the newly parsed function is not the expected one
DeclaratorIdAST *newDeclId = getDeclaratorId(newDef->declarator);
if (!newDeclId || !newDeclId->name || !newDeclId->name->name
- || overview.prettyName(newDeclId->name->name) != nameInitial) {
+ || overview.prettyName(newDeclId->name->name) != normalizedInitialName()) {
return changes;
}
@@ -939,6 +940,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);
@@ -953,5 +978,28 @@ ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targetOffse
return changes;
}
+// Only has an effect with operators.
+// Makes sure there is exactly one space between the "operator" string
+// and the actual operator, as that is what it will be compared against.
+QString FunctionDeclDefLink::normalizedInitialName() const
+{
+ QString n = nameInitial;
+ const QString op = "operator";
+ int index = n.indexOf(op);
+ if (index == -1)
+ return n;
+ if (index > 0 && n.at(index - 1).isLetterOrNumber())
+ return n;
+ index += op.length();
+ if (index == n.length())
+ return n;
+ if (n.at(index).isLetterOrNumber())
+ return n;
+ n.insert(index++, ' ');
+ while (index < n.length() && n.at(index) == ' ')
+ n.remove(index, 1);
+ return n;
+}
+
} // namespace Internal
} // namespace CppEditor