Fixed #4880 (false negative: uninitialized variable, handling of conditional noreturn scopes)
This commit is contained in:
parent
53e2d425d1
commit
42c4aa1c49
|
@ -1226,7 +1226,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
|
|||
if (_tokenizer->IsScopeNoReturn(tok)) {
|
||||
if (noreturn)
|
||||
*noreturn = true;
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
@ -2112,6 +2112,16 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVarB("int foo(int a) {\n" // #4880
|
||||
" int x;\n"
|
||||
" if (a==1)\n"
|
||||
" g(1);\n" // might be a noreturn function
|
||||
" if (a==17)\n"
|
||||
" g(2);\n" // might be a noreturn function
|
||||
" return x;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: x\n", errout.str());
|
||||
|
||||
checkUninitVarB("void (*init)(char *str);\n"
|
||||
"\n"
|
||||
"char x() {\n"
|
||||
|
|
Loading…
Reference in New Issue