QuickFix: Fix generate function definition with unsigned type

Fixes: QTCREATORBUG-28378
Change-Id: Ic94901e430d08aab22c8f4c394eda1f8a93398bc
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Artem Sokolovskii
2022-10-31 16:31:20 +01:00
parent 421e5d9c59
commit 39d04fb9e7
4 changed files with 113 additions and 1 deletions

View File

@@ -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:

View File

@@ -300,6 +300,7 @@ private:
int _methodKey;
bool _skipFunctionBodies;
int _depth;
bool _typeWasUnsignedOrSigned = false;
};
} // namespace CPlusPlus

View File

@@ -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<signed> g);
myclass(QVector<unsigned> g);
}
)--";
expected =R"--(
class myclass
{
myclass(QVector<signed> g);
myclass(QVector<unsigned> g);
}
myclass::myclass(QVector<signed int> g)
{
}
)--";
QuickFixOperationTest(singleDocument(original, expected), &factory);
original =R"--(
class myclass
{
myclass(QVector<signed> g);
myc@lass(QVector<unsigned> g);
}
)--";
expected =R"--(
class myclass
{
myclass(QVector<signed> g);
myclass(QVector<unsigned> g);
}
myclass::myclass(QVector<unsigned int> 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 =

View File

@@ -133,6 +133,7 @@ private slots:
void testInsertDefFromDeclTemplateClass();
void testInsertDefFromDeclTemplateClassWithValueParam();
void testInsertDefFromDeclTemplateFunction();
void testInsertDefFromDeclFunctionWithSignedUnsignedArgument();
void testInsertDefFromDeclNotTriggeredForFriendFunc();
void testInsertDefFromDeclMinimalFunctionParameterType();
void testInsertDefFromDeclAliasTemplateAsReturnType();