Skip to content

Commit 815f861

Browse files
Update testuninitvar.cpp
1 parent a6863fc commit 815f861

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

‎test/testuninitvar.cpp‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3719,13 +3719,14 @@ class TestUninitVar : public TestFixture {
37193719

37203720
#define valueFlowUninit(...) valueFlowUninit_(__FILE__, __LINE__, __VA_ARGS__)
37213721
template<size_t size>
3722-
void valueFlowUninit_(const char* file, int line, const char (&code)[size], bool cpp = true)
3722+
void valueFlowUninit_(const char* file, int line, const char (&code)[size], bool cpp = true, const Settings* pSettings)
37233723
{
3724-
SimpleTokenizer tokenizer(settings, *this, cpp);
3724+
const Settings& s = pSettings ? *pSettings : settings;
3725+
SimpleTokenizer tokenizer(s, *this, cpp);
37253726
ASSERT_LOC(tokenizer.tokenize(code), file, line);
37263727

37273728
// Check for redundant code..
3728-
CheckUninitVarImpl checkuninitvar(&tokenizer, settings, *this);
3729+
CheckUninitVarImpl checkuninitvar(&tokenizer, s, *this);
37293730
(checkuninitvar.valueFlowUninit)();
37303731
}
37313732

@@ -7945,6 +7946,24 @@ class TestUninitVar : public TestFixture {
79457946
ASSERT_EQUALS("", errout_str());
79467947
}
79477948

7949+
void valueFlowUninitErrorPath()
7950+
{
7951+
setMultiline();
7952+
Settings s = settings;
7953+
s.templateLocation = "{file}:{line}:note:{info}\n";
7954+
valueFlowUninit("void f(bool b) {\n"
7955+
" int i;\n"
7956+
" if (b)\n"
7957+
" return i;\n"
7958+
" i = 1;\n"
7959+
" return i;\n"
7960+
"}\n", &s);
7961+
ASSERT_EQUALS("[test.cpp:4:16]: warning: Uninitialized variable: i [uninitvar]\n"
7962+
"[test.cpp:3:9]: note: Assuming condition is true\n"
7963+
"[test.cpp:4:16]: note: Uninitialized variable: i\n",
7964+
errout_str());
7965+
}
7966+
79487967
void uninitvar_memberfunction() {
79497968
// # 8715
79507969
valueFlowUninit("struct C {\n"

0 commit comments

Comments
 (0)