From c7886ca1c4a4fc96e7cdcb4debed3808b59bd370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 3 Sep 2011 18:53:14 +0200 Subject: [PATCH] Fixed #3058 (False positive: Uninitialized variable: data) --- lib/checkuninitvar.cpp | 6 +++++- test/testuninitvar.cpp | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 5b307052f..0e019dbd5 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -510,7 +510,11 @@ private: // Used.. if (Token::Match(tok.previous(), "[[(,+-*/|=] %var% ]|)|,|;|%op%")) { - use(checks, &tok); + // initialize reference variable + if (Token::Match(tok.tokAt(-3), "& %var% =")) + bailOutVar(checks, tok.varId()); + else + use(checks, &tok); return &tok; } diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 5bf7e6113..27bb47110 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -155,6 +155,13 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar("void foo()\n" + "{\n" + " int *x;\n" + " int *&y = x;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + checkUninitVar("void foo()\n" "{\n" " int x = xyz::x;\n"