From ce5c38f52c2af71796924e1463890bde39bf3ed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 19 Jun 2012 20:04:10 +0200 Subject: [PATCH] Fixed #3890 (False positive Uninitialized variable on returning default value on a class member) --- lib/checkuninitvar.cpp | 3 ++- test/testuninitvar.cpp | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index b29ffa302..def045c35 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1054,9 +1054,10 @@ void CheckUninitVar::checkScope(const Scope* scope) bool stdtype = false; const Token* tok = i->typeStartToken(); - for (; tok->str() != ";"; tok = tok->next()) + for (; tok->str() != ";" && tok->str() != "<"; tok = tok->next()) { if (tok->isStandardType()) stdtype = true; + } if (stdtype || i->isPointer()) checkScopeForVariable(tok, *i, NULL); diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 4818d29be..66be4ca34 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -2150,6 +2150,14 @@ private: " int a, a2, a2*x; if () ;\n" " )\n" "}\n"); + + // Ticket #3890 - False positive for std::map + checkUninitVar2("void f() {\n" + " std::map x;\n" + " return x;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } // #3869 - reference variable