Fixed #3924 (False positive: Uninitialized variable (const pointer))
This commit is contained in:
parent
cb7757f650
commit
bb9f114d84
|
@ -1886,6 +1886,9 @@ bool Tokenizer::tokenize(std::istream &code,
|
||||||
tok = fortok;
|
tok = fortok;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
// Convert "type const" to "const type"
|
||||||
|
typeConstToConstType();
|
||||||
|
|
||||||
simplifyConst();
|
simplifyConst();
|
||||||
|
|
||||||
// struct simplification "struct S {} s; => struct S { } ; S s ;
|
// struct simplification "struct S {} s; => struct S { } ; S s ;
|
||||||
|
@ -7963,6 +7966,20 @@ void Tokenizer::simplifyComparisonOrder()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tokenizer::typeConstToConstType()
|
||||||
|
{
|
||||||
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
|
if (tok->isStandardType() && Token::simpleMatch(tok->next(), "const")) {
|
||||||
|
tok->next()->str(tok->str());
|
||||||
|
tok->str("const");
|
||||||
|
} else if (Token::Match(tok, "struct %type% const")) {
|
||||||
|
tok->next()->next()->str(tok->next()->str());
|
||||||
|
tok->str("const");
|
||||||
|
tok->next()->str("struct");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Tokenizer::simplifyConst()
|
void Tokenizer::simplifyConst()
|
||||||
{
|
{
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
|
|
|
@ -482,6 +482,12 @@ public:
|
||||||
*/
|
*/
|
||||||
void simplifyComparisonOrder();
|
void simplifyComparisonOrder();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* simplify "type const" to "const type"
|
||||||
|
* For example: int const x => const int x
|
||||||
|
*/
|
||||||
|
void typeConstToConstType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change "int const x;" into "const int x;"
|
* Change "int const x;" into "const int x;"
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -57,6 +57,8 @@ private:
|
||||||
TEST_CASE(tokenize22); // special marker $ from preprocessor
|
TEST_CASE(tokenize22); // special marker $ from preprocessor
|
||||||
TEST_CASE(tokenize23); // tokenize "return - __LINE__;"
|
TEST_CASE(tokenize23); // tokenize "return - __LINE__;"
|
||||||
|
|
||||||
|
TEST_CASE(typeConstToConstType); // change "int const" to "const int".
|
||||||
|
|
||||||
// don't freak out when the syntax is wrong
|
// don't freak out when the syntax is wrong
|
||||||
TEST_CASE(wrong_syntax1);
|
TEST_CASE(wrong_syntax1);
|
||||||
TEST_CASE(wrong_syntax2);
|
TEST_CASE(wrong_syntax2);
|
||||||
|
@ -623,6 +625,11 @@ private:
|
||||||
ASSERT_EQUALS("return -1 ;", tokenizeAndStringify("return - __LINE__;"));
|
ASSERT_EQUALS("return -1 ;", tokenizeAndStringify("return - __LINE__;"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void typeConstToConstType() { // change "int const" to "const int".
|
||||||
|
ASSERT_EQUALS("const int x ;", tokenizeAndStringify("int const x;"));
|
||||||
|
ASSERT_EQUALS("const struct X x ;", tokenizeAndStringify("struct X const x;"));
|
||||||
|
}
|
||||||
|
|
||||||
void wrong_syntax1() {
|
void wrong_syntax1() {
|
||||||
{
|
{
|
||||||
const std::string code("TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))");
|
const std::string code("TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))");
|
||||||
|
@ -3221,7 +3228,7 @@ private:
|
||||||
{
|
{
|
||||||
const std::string code = "static int const SZ = 22;\n";
|
const std::string code = "static int const SZ = 22;\n";
|
||||||
ASSERT_EQUALS("\n\n##file 0\n"
|
ASSERT_EQUALS("\n\n##file 0\n"
|
||||||
"1: static int const SZ@1 = 22 ;\n",
|
"1: const static int SZ@1 = 22 ;\n",
|
||||||
tokenizeDebugListing(code, false, "test.c"));
|
tokenizeDebugListing(code, false, "test.c"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue