Ticket #5776: Simplify (&a)->b into a.b

This commit is contained in:
Simon Martin 2015-07-17 23:27:35 +02:00
parent 5e74125375
commit 1f73d71542
2 changed files with 19 additions and 1 deletions

View File

@ -1886,8 +1886,17 @@ void Tokenizer::combineOperators()
continue;
}
// replace "->" with "."
// simplify "->"
else if (c1 == '-' && c2 == '>') {
// If the preceding sequence is "( & %name% )", replace it by "%name%"
Token *t = tok->tokAt(-4);
if (t && Token::Match(t, "( & %name% )")) {
t->deleteThis();
t->deleteThis();
t->deleteNext();
tok = t->next();
}
// Replace "->" with "."
tok->str(".");
tok->originalName("->");
tok->deleteNext();

View File

@ -3547,6 +3547,15 @@ private:
" x = a.m;\n"
"}");
ASSERT_EQUALS("", errout.str());
// Ticket #5776
checkUninitVar2("typedef struct { int a, b; } AB;\n"
"void f(void) {\n"
" AB ab;\n"
" ab.a = 1;\n"
" return (&ab)->b;\n"
"}", "test.c");
ASSERT_EQUALS("[test.c:5]: (error) Uninitialized struct member: ab.b\n", errout.str());
}
void uninitvar2_while() {