Fixed false positive for *a++ in for-loop condition

Moved unit test to testgarbage.cpp
This commit is contained in:
PKEuS 2015-05-07 20:34:57 +02:00
parent f430748e0c
commit 22fbc18fb7
3 changed files with 19 additions and 12 deletions

View File

@ -309,7 +309,7 @@ void CheckOther::clarifyStatement()
while (tok2 && tok2->str() == "*") while (tok2 && tok2->str() == "*")
tok2 = tok2->previous(); tok2 = tok2->previous();
if (Token::Match(tok2, "[{};]")) { if (!tok2->astParent() && Token::Match(tok2, "[{};]")) {
tok2 = tok->astOperand1(); tok2 = tok->astOperand1();
if (Token::Match(tok2, "++|-- [;,]")) if (Token::Match(tok2, "++|-- [;,]"))
clarifyStatementError(tok2); clarifyStatementError(tok2);

View File

@ -75,6 +75,7 @@ private:
TEST_CASE(garbageCode34); // #6626 TEST_CASE(garbageCode34); // #6626
TEST_CASE(garbageCode35); // #2599, #2604 TEST_CASE(garbageCode35); // #2599, #2604
TEST_CASE(garbageCode36); // #6334 TEST_CASE(garbageCode36); // #6334
TEST_CASE(garbageCode37); // #5166
TEST_CASE(garbageValueFlow); TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageSymbolDatabase);
@ -430,6 +431,20 @@ private:
checkCode("sizeof <= A"); checkCode("sizeof <= A");
} }
void garbageCode36() { // #6334
checkCode("{ } < class template < > , { = } ; class... >\n"
"struct Y { }\n"
"class Types { }\n"
"( X < int > \"uses template\" ) ( < ( ) \"uses ; \n"
"( int int ::primary \"uses template\" ) int double \"uses )\n"
"::primary , \"uses template\" ;\n");
}
void garbageCode37() {
// #5166 segmentation fault (invalid code) in lib/checkother.cpp:329 ( void * f { } void b ( ) { * f } )
checkCode("void * f { } void b ( ) { * f }");
}
void garbageValueFlow() { void garbageValueFlow() {
// #6089 // #6089
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n" const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"
@ -544,15 +559,6 @@ private:
"}\n" "}\n"
); );
} }
void garbageCode36() { // #6334
checkCode("{ } < class template < > , { = } ; class... >\n"
"struct Y { }\n"
"class Types { }\n"
"( X < int > \"uses template\" ) ( < ( ) \"uses ; \n"
"( int int ::primary \"uses template\" ) int double \"uses )\n"
"::primary , \"uses template\" ;\n");
}
}; };
REGISTER_TEST(TestGarbage) REGISTER_TEST(TestGarbage)

View File

@ -3843,8 +3843,9 @@ private:
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #5166 segmentation fault (invalid code) in lib/checkother.cpp:329 ( void * f { } void b ( ) { * f } ) check("void *f(char* p) {\n"
check("void * f { } void b ( ) { * f }"); " for (p = path; *p++;) ;\n"
"}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }