Fix #10698 FP uninitvar with new and braced initializer (#3934)

This commit is contained in:
chrchr-github 2022-03-24 20:08:51 +01:00 committed by GitHub
parent a7606b72ec
commit 479af21405
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 2 deletions

View File

@ -913,6 +913,8 @@ static bool isPrefixUnary(const Token* tok, bool cpp)
static void compilePrecedence2(Token *&tok, AST_state& state)
{
const bool isStartOfCpp11Init = state.cpp && tok && tok->str() == "{" && iscpp11init(tok);
if (!(isStartOfCpp11Init && Token::Match(tok->tokAt(-2), "new %type% {")))
compileScope(tok, state);
while (tok) {
if (tok->tokType() == Token::eIncDecOp && !isPrefixUnary(tok, state.cpp)) {

View File

@ -7889,7 +7889,7 @@ static void valueFlowDynamicBufferSize(TokenList* tokenlist, SymbolDatabase* sym
else {
typeTok = newTok->astOperand1();
if (typeTok && typeTok->str() == "{")
typeTok = typeTok->astOperand2();
typeTok = typeTok->astOperand1();
}
if (bracTok && bracTok->astOperand2() && bracTok->astOperand2()->hasKnownIntValue())
numElem = bracTok->astOperand2()->getKnownIntValue();

View File

@ -6030,6 +6030,8 @@ private:
ASSERT_EQUALS("aA1(new(bB2(new(,", testAst("a(new A(1)), b(new B(2))"));
ASSERT_EQUALS("Fred10[new", testAst(";new Fred[10];"));
ASSERT_EQUALS("adelete", testAst("void f() { delete a; }"));
ASSERT_EQUALS("Aa*A{new=", testAst("A* a = new A{};"));
ASSERT_EQUALS("Aa*A12,{new=", testAst("A* a = new A{ 1, 2 };"));
// placement new
ASSERT_EQUALS("X12,3,(new ab,c,", testAst("new (a,b,c) X(1,2,3);"));

View File

@ -2024,6 +2024,12 @@ private:
" a = *pBuf;\n"
"}", "test.c");
ASSERT_EQUALS("", errout.str());
checkUninitVar("class A {};\n" // #10698
"void f() {\n"
" A* a = new A{};\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
// class / struct..