diff --git a/src/libs/3rdparty/cplusplus/Bind.cpp b/src/libs/3rdparty/cplusplus/Bind.cpp index 4ad562eb0c6..effaac4b65a 100644 --- a/src/libs/3rdparty/cplusplus/Bind.cpp +++ b/src/libs/3rdparty/cplusplus/Bind.cpp @@ -276,8 +276,25 @@ FullySpecifiedType Bind::postfixDeclarator(PostfixDeclaratorAST *ast, const Full return value; } -bool Bind::preVisit(AST *) +bool Bind::preVisit(AST *ast) { + if (_typeWasUnsignedOrSigned) { + if (SimpleSpecifierAST *simpleAst = ast->asSimpleSpecifier()) { + switch (tokenKind(simpleAst->specifier_token)) { + case T_CHAR: + case T_CHAR16_T: + case T_CHAR32_T: + case T_WCHAR_T: + case T_INT: + case T_SHORT: + case T_LONG: + _type.setType(&UndefinedType::instance); + break; + } + } + _typeWasUnsignedOrSigned = false; + } + ++_depth; if (_depth > kMaxDepth) return false; @@ -2980,13 +2997,17 @@ bool Bind::visit(SimpleSpecifierAST *ast) case T_SIGNED: if (_type.isSigned()) translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token)); + _type.setType(control()->integerType(IntegerType::Int)); _type.setSigned(true); + _typeWasUnsignedOrSigned = true; break; case T_UNSIGNED: if (_type.isUnsigned()) translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token)); + _type.setType(control()->integerType(IntegerType::Int)); _type.setUnsigned(true); + _typeWasUnsignedOrSigned = true; break; case T_CHAR: diff --git a/src/libs/3rdparty/cplusplus/Bind.h b/src/libs/3rdparty/cplusplus/Bind.h index e5ee6228814..3947e57026d 100644 --- a/src/libs/3rdparty/cplusplus/Bind.h +++ b/src/libs/3rdparty/cplusplus/Bind.h @@ -300,6 +300,7 @@ private: int _methodKey; bool _skipFunctionBodies; int _depth; + bool _typeWasUnsignedOrSigned = false; }; } // namespace CPlusPlus diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index 060eb808a93..bbd192f7f74 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -4713,6 +4713,95 @@ void QuickfixTest::testInsertDefFromDeclTemplateFunction() QuickFixOperationTest(singleDocument(original, expected), &factory); } +void QuickfixTest::testInsertDefFromDeclFunctionWithSignedUnsignedArgument() +{ + QByteArray original; + QByteArray expected; + InsertDefFromDecl factory; + + original =R"--( +class myclass +{ + myc@lass(QVector g); + myclass(QVector g); +} +)--"; + expected =R"--( +class myclass +{ + myclass(QVector g); + myclass(QVector g); +} + +myclass::myclass(QVector g) +{ + +} +)--"; + + QuickFixOperationTest(singleDocument(original, expected), &factory); + + original =R"--( +class myclass +{ + myclass(QVector g); + myc@lass(QVector g); +} +)--"; + expected =R"--( +class myclass +{ + myclass(QVector g); + myclass(QVector g); +} + +myclass::myclass(QVector g) +{ + +} +)--"; + + QuickFixOperationTest(singleDocument(original, expected), &factory); + + original =R"--( +class myclass +{ + unsigned f@oo(unsigned); +} +)--"; + expected =R"--( +class myclass +{ + unsigned foo(unsigned); +} + +unsigned int myclass::foo(unsigned int) +{ + +} +)--"; + QuickFixOperationTest(singleDocument(original, expected), &factory); + + original =R"--( +class myclass +{ + signed f@oo(signed); +} +)--"; + expected =R"--( +class myclass +{ + signed foo(signed); +} + +signed int myclass::foo(signed int) +{ + +} +)--"; + QuickFixOperationTest(singleDocument(original, expected), &factory); +} + void QuickfixTest::testInsertDefFromDeclNotTriggeredForFriendFunc() { const QByteArray contents = diff --git a/src/plugins/cppeditor/cppquickfix_test.h b/src/plugins/cppeditor/cppquickfix_test.h index f381294a25e..2a72e45df55 100644 --- a/src/plugins/cppeditor/cppquickfix_test.h +++ b/src/plugins/cppeditor/cppquickfix_test.h @@ -133,6 +133,7 @@ private slots: void testInsertDefFromDeclTemplateClass(); void testInsertDefFromDeclTemplateClassWithValueParam(); void testInsertDefFromDeclTemplateFunction(); + void testInsertDefFromDeclFunctionWithSignedUnsignedArgument(); void testInsertDefFromDeclNotTriggeredForFriendFunc(); void testInsertDefFromDeclMinimalFunctionParameterType(); void testInsertDefFromDeclAliasTemplateAsReturnType();