From 85d83d86ac46738e56c2cc4fb4ede5acf3960431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 4 Sep 2011 12:53:53 +0200 Subject: [PATCH] Fixed #3060 (False positive: Uninitialized variable: fresh) --- lib/checkuninitvar.cpp | 4 +++- test/testuninitvar.cpp | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 0e019dbd5..af1c963b5 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -596,8 +596,10 @@ private: return tok.tokAt(3); } - else if (Token::simpleMatch(tok.previous(), ">>") || Token::simpleMatch(tok.next(), "=")) + else if (Token::Match(tok.previous(), "<<|>>") || Token::simpleMatch(tok.next(), "=")) { + // TODO: Don't bail out for "<<" and ">>" if these are + // just computations ExecutionPath::bailOutVar(checks, tok.varId()); return &tok; } diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 27bb47110..6112fa552 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -322,6 +322,13 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar("int a(FArchive &arc) {\n" // #3060 (initialization through operator<<) + " int *p;\n" + " arc << p;\n" + " return *p;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + checkUninitVar("int a()\n" "{\n" " int ret;\n"