diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5afd710b3..ea444460b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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(); diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 30ddf2431..a35a346d7 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -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() {