forked from qt-creator/qt-creator
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:
23
src/libs/3rdparty/cplusplus/Bind.cpp
vendored
23
src/libs/3rdparty/cplusplus/Bind.cpp
vendored
@@ -276,8 +276,25 @@ FullySpecifiedType Bind::postfixDeclarator(PostfixDeclaratorAST *ast, const Full
|
|||||||
return value;
|
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;
|
++_depth;
|
||||||
if (_depth > kMaxDepth)
|
if (_depth > kMaxDepth)
|
||||||
return false;
|
return false;
|
||||||
@@ -2980,13 +2997,17 @@ bool Bind::visit(SimpleSpecifierAST *ast)
|
|||||||
case T_SIGNED:
|
case T_SIGNED:
|
||||||
if (_type.isSigned())
|
if (_type.isSigned())
|
||||||
translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
|
translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
|
||||||
|
_type.setType(control()->integerType(IntegerType::Int));
|
||||||
_type.setSigned(true);
|
_type.setSigned(true);
|
||||||
|
_typeWasUnsignedOrSigned = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_UNSIGNED:
|
case T_UNSIGNED:
|
||||||
if (_type.isUnsigned())
|
if (_type.isUnsigned())
|
||||||
translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
|
translationUnit()->error(ast->specifier_token, "duplicate `%s'", spell(ast->specifier_token));
|
||||||
|
_type.setType(control()->integerType(IntegerType::Int));
|
||||||
_type.setUnsigned(true);
|
_type.setUnsigned(true);
|
||||||
|
_typeWasUnsignedOrSigned = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_CHAR:
|
case T_CHAR:
|
||||||
|
1
src/libs/3rdparty/cplusplus/Bind.h
vendored
1
src/libs/3rdparty/cplusplus/Bind.h
vendored
@@ -300,6 +300,7 @@ private:
|
|||||||
int _methodKey;
|
int _methodKey;
|
||||||
bool _skipFunctionBodies;
|
bool _skipFunctionBodies;
|
||||||
int _depth;
|
int _depth;
|
||||||
|
bool _typeWasUnsignedOrSigned = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CPlusPlus
|
} // namespace CPlusPlus
|
||||||
|
@@ -4713,6 +4713,95 @@ void QuickfixTest::testInsertDefFromDeclTemplateFunction()
|
|||||||
QuickFixOperationTest(singleDocument(original, expected), &factory);
|
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()
|
void QuickfixTest::testInsertDefFromDeclNotTriggeredForFriendFunc()
|
||||||
{
|
{
|
||||||
const QByteArray contents =
|
const QByteArray contents =
|
||||||
|
@@ -133,6 +133,7 @@ private slots:
|
|||||||
void testInsertDefFromDeclTemplateClass();
|
void testInsertDefFromDeclTemplateClass();
|
||||||
void testInsertDefFromDeclTemplateClassWithValueParam();
|
void testInsertDefFromDeclTemplateClassWithValueParam();
|
||||||
void testInsertDefFromDeclTemplateFunction();
|
void testInsertDefFromDeclTemplateFunction();
|
||||||
|
void testInsertDefFromDeclFunctionWithSignedUnsignedArgument();
|
||||||
void testInsertDefFromDeclNotTriggeredForFriendFunc();
|
void testInsertDefFromDeclNotTriggeredForFriendFunc();
|
||||||
void testInsertDefFromDeclMinimalFunctionParameterType();
|
void testInsertDefFromDeclMinimalFunctionParameterType();
|
||||||
void testInsertDefFromDeclAliasTemplateAsReturnType();
|
void testInsertDefFromDeclAliasTemplateAsReturnType();
|
||||||
|
Reference in New Issue
Block a user