From fb6c7f33f0b373c7f291742413fb4f0fedd96015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 24 Apr 2012 19:50:54 +0200 Subject: [PATCH] Fixed #3707 (Uninitialized variable with operator >> and templates) --- lib/checkuninitvar.cpp | 24 ++++++++++++++++++------ test/testuninitvar.cpp | 7 +++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index ba68e434c..3e09f9028 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -521,14 +521,26 @@ private: } } else { const Token *tok2 = tok.next(); - if (tok2->str() == "[" && Token::simpleMatch(tok2->link(), "] =")) { - if (use_dead_pointer(checks, &tok)) { - return &tok; - } - parserhs(tok2, checks); - tok2 = tok2->link()->next(); + if (tok2->str() == "[") { + const Token *tok3 = tok2->link(); + while (Token::simpleMatch(tok3, "] [")) + tok3 = tok3->next()->link(); + + // Possible initialization + if (Token::simpleMatch(tok3, "] >>")) + return &tok; + + if (Token::simpleMatch(tok3, "] =")) { + if (use_dead_pointer(checks, &tok)) { + return &tok; + } + + parserhs(tok2, checks); + tok2 = tok3->next(); + } } + parserhs(tok2, checks); } diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 30d606542..1f1c00b57 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -335,6 +335,13 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar("void foo() {\n" // #3707 + " Node node;\n" + " int x;\n" + " node[\"abcd\"] >> x;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + checkUninitVar("int a(FArchive &arc) {\n" // #3060 (initialization through operator<<) " int *p;\n" " arc << p;\n"