From dc6aa92f3b171ce6eefd3be7c316d1547a297e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 21 Dec 2012 18:50:38 +0100 Subject: [PATCH] Uninitialized variables: warn about structs in C code --- lib/checkuninitvar.cpp | 2 +- test/testuninitvar.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 4b808c1d9..6e60963e6 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1055,7 +1055,7 @@ void CheckUninitVar::check() void CheckUninitVar::checkScope(const Scope* scope) { for (std::list::const_iterator i = scope->varlist.begin(); i != scope->varlist.end(); ++i) { - if ((i->type() && !i->isPointer()) || i->isStatic() || i->isExtern() || i->isConst() || i->isArray() || i->isReference()) + if ((_tokenizer->isCPP() && i->type() && !i->isPointer()) || i->isStatic() || i->isExtern() || i->isConst() || i->isArray() || i->isReference()) continue; if (i->nameToken()->strAt(1) == "(") continue; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 8fcfe3cca..75e3f27b3 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -2373,6 +2373,16 @@ private: // Assume dfs is a POD type if file is C checkUninitVar2(code, "test.c"); ASSERT_EQUALS("[test.c:3]: (error) Uninitialized variable: a\n", errout.str()); + + const char code2[] = "struct AB { int a,b; };\n" + "void f() {\n" + " struct AB ab;\n" + " return ab;\n" + "}"; + checkUninitVar2(code2, "test.cpp"); + ASSERT_EQUALS("", errout.str()); + checkUninitVar2(code2, "test.c"); + ASSERT_EQUALS("[test.c:4]: (error) Uninitialized variable: ab\n", errout.str()); } // Handling of function calls