Skip to content

Commit f2238e7

Browse files
Fix crash in isTemporary() (#4866)
1 parent 7ce82e4 commit f2238e7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/astutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ bool isTemporary(bool cpp, const Token* tok, const Library* library, bool unknow
407407
return false;
408408
if (Token::simpleMatch(tok, "?")) {
409409
const Token* branchTok = tok->astOperand2();
410-
if (!branchTok->astOperand1()->valueType())
410+
if (!branchTok->astOperand1() || !branchTok->astOperand1()->valueType())
411411
return false;
412412
if (!branchTok->astOperand2()->valueType())
413413
return false;

test/testvalueflow.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6870,6 +6870,15 @@ class TestValueFlow : public TestFixture {
68706870
" g(x < y ? : 1);\n"
68716871
"};\n";
68726872
valueOfTok(code, "?");
6873+
6874+
code = "struct C {\n"
6875+
" explicit C(bool);\n"
6876+
" operator bool();\n"
6877+
"};\n"
6878+
"void f(bool b) {\n"
6879+
" const C& c = C(b) ? : C(false);\n"
6880+
"};\n";
6881+
valueOfTok(code, "?");
68736882
}
68746883

68756884
void valueFlowHang() {

0 commit comments

Comments
 (0)