From 915acac0b865eb3fc8d70aa36fd61712e43d3bb2 Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Sat, 22 Sep 2018 16:52:34 +0200 Subject: [PATCH] Ticket #8734: Skip static member variables in CheckUninitVar. (#1388) --- lib/checkuninitvar.cpp | 3 ++- test/testuninitvar.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 69acbea3e..88d29437b 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -170,7 +170,8 @@ void CheckUninitVar::checkStruct(const Token *tok, const Variable &structvar) for (std::list::const_iterator it = scope2->varlist.begin(); it != scope2->varlist.end(); ++it) { const Variable &var = *it; - if (var.hasDefault() || var.isArray() || (!mTokenizer->isC() && var.isClass() && (!var.type() || var.type()->needInitialization != Type::True))) + if (var.isStatic() || var.hasDefault() || var.isArray() || + (!mTokenizer->isC() && var.isClass() && (!var.type() || var.type()->needInitialization != Type::True))) continue; // is the variable declared in a inner union? diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 99299370e..85994eebe 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -75,6 +75,7 @@ private: TEST_CASE(uninitvar_pointertoarray); TEST_CASE(uninitvar_cpp11ArrayInit); // #7010 TEST_CASE(uninitvar_rangeBasedFor); // #7078 + TEST_CASE(uninitvar_static); // #8734 TEST_CASE(trac_4871); TEST_CASE(syntax_error); // Ticket #5073 TEST_CASE(trac_5970); @@ -3811,6 +3812,21 @@ private: ASSERT_EQUALS("", errout.str()); } + void uninitvar_static() { // #8734 + checkUninitVar("struct X { " + " typedef struct { int p; } P_t; " + " static int arr[]; " + "}; " + "int X::arr[] = {42}; " + "void f() { " + " std::vector result; " + " X::P_t P; " + " P.p = 0; " + " result.push_back(P); " + "}"); + ASSERT_EQUALS("", errout.str()); + } + void trac_4871() { // #4871 checkUninitVar("void pickup(int a) {\n" "bool using_planner_action;\n"