Fix crash in isTemporary() (#4866)

This commit is contained in:
chrchr-github 2023-03-07 12:44:54 +01:00 committed by GitHub
parent 7ce82e4fcb
commit f2238e717b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -407,7 +407,7 @@ bool isTemporary(bool cpp, const Token* tok, const Library* library, bool unknow
return false; return false;
if (Token::simpleMatch(tok, "?")) { if (Token::simpleMatch(tok, "?")) {
const Token* branchTok = tok->astOperand2(); const Token* branchTok = tok->astOperand2();
if (!branchTok->astOperand1()->valueType()) if (!branchTok->astOperand1() || !branchTok->astOperand1()->valueType())
return false; return false;
if (!branchTok->astOperand2()->valueType()) if (!branchTok->astOperand2()->valueType())
return false; return false;

View File

@ -6870,6 +6870,15 @@ private:
" g(x < y ? : 1);\n" " g(x < y ? : 1);\n"
"};\n"; "};\n";
valueOfTok(code, "?"); valueOfTok(code, "?");
code = "struct C {\n"
" explicit C(bool);\n"
" operator bool();\n"
"};\n"
"void f(bool b) {\n"
" const C& c = C(b) ? : C(false);\n"
"};\n";
valueOfTok(code, "?");
} }
void valueFlowHang() { void valueFlowHang() {