Merge pull request #623 from simartin/ticket_5776

Ticket #5776: Simplify (&a)->b into a.b
This commit is contained in:
orbitcowboy 2015-07-18 09:24:55 +02:00
commit 3daabbcc3b
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() {