Ticket #5776: Simplify (&a)->b into a.b
This commit is contained in:
parent
5e74125375
commit
1f73d71542
|
@ -1886,8 +1886,17 @@ void Tokenizer::combineOperators()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace "->" with "."
|
// simplify "->"
|
||||||
else if (c1 == '-' && c2 == '>') {
|
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->str(".");
|
||||||
tok->originalName("->");
|
tok->originalName("->");
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
|
|
|
@ -3547,6 +3547,15 @@ private:
|
||||||
" x = a.m;\n"
|
" x = a.m;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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() {
|
void uninitvar2_while() {
|
||||||
|
|
Loading…
Reference in New Issue