forked from qt-creator/qt-creator
C++: Support negative enum values
Change-Id: I93dac08a62be467918dbc9f72239d34191a81fd6 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
4dd4b180f3
commit
ebf26ca125
5
src/libs/3rdparty/cplusplus/Bind.cpp
vendored
5
src/libs/3rdparty/cplusplus/Bind.cpp
vendored
@@ -468,7 +468,10 @@ bool isInteger(const StringLiteral *stringLiteral)
|
|||||||
{
|
{
|
||||||
const int size = stringLiteral->size();
|
const int size = stringLiteral->size();
|
||||||
const char *chars = stringLiteral->chars();
|
const char *chars = stringLiteral->chars();
|
||||||
for (int i = 0; i < size; ++i) {
|
int i = 0;
|
||||||
|
if (chars[i] == '-')
|
||||||
|
++i;
|
||||||
|
for (; i < size; ++i) {
|
||||||
if (!isdigit(chars[i]))
|
if (!isdigit(chars[i]))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -190,6 +190,7 @@ private slots:
|
|||||||
void enum_constantValue3();
|
void enum_constantValue3();
|
||||||
void enum_constantValue4();
|
void enum_constantValue4();
|
||||||
void enum_constantValue5();
|
void enum_constantValue5();
|
||||||
|
void enum_constantValueNegative();
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_Semantic::function_declaration_1()
|
void tst_Semantic::function_declaration_1()
|
||||||
@@ -916,5 +917,28 @@ void tst_Semantic::enum_constantValue5()
|
|||||||
testEnumaratorDeclarator(e, 4, "2");
|
testEnumaratorDeclarator(e, 4, "2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_Semantic::enum_constantValueNegative()
|
||||||
|
{
|
||||||
|
QSharedPointer<Document> doc = document(
|
||||||
|
"enum {\n"
|
||||||
|
" E1=-2,\n"
|
||||||
|
" E2,\n"
|
||||||
|
" E3,\n"
|
||||||
|
" E4\n"
|
||||||
|
"};\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
QCOMPARE(doc->errorCount, 0U);
|
||||||
|
QCOMPARE(doc->globals->memberCount(), 1U);
|
||||||
|
Enum *e = doc->globals->memberAt(0)->asEnum();
|
||||||
|
QVERIFY(e);
|
||||||
|
QCOMPARE(e->memberCount(), 4U);
|
||||||
|
|
||||||
|
testEnumaratorDeclarator(e, 0, "-2");
|
||||||
|
testEnumaratorDeclarator(e, 1, "-1");
|
||||||
|
testEnumaratorDeclarator(e, 2, "0");
|
||||||
|
testEnumaratorDeclarator(e, 3, "1");
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_Semantic)
|
QTEST_MAIN(tst_Semantic)
|
||||||
#include "tst_semantic.moc"
|
#include "tst_semantic.moc"
|
||||||
|
|||||||
Reference in New Issue
Block a user