@@ -376,6 +376,19 @@ static void combineValueProperties(const ValueFlow::Value &value1, const ValueFl
376
376
result->errorPath = (value1.errorPath .empty () ? value2 : value1).errorPath ;
377
377
}
378
378
379
+
380
+ static const Token *getCastTypeStartToken (const Token *parent)
381
+ {
382
+ // TODO: This might be a generic utility function?
383
+ if (!parent || parent->str () != " (" )
384
+ return nullptr ;
385
+ if (!parent->astOperand2 () && Token::Match (parent," ( %name%" ))
386
+ return parent->next ();
387
+ if (parent->astOperand2 () && Token::Match (parent->astOperand1 (), " const_cast|dynamic_cast|reinterpret_cast|static_cast <" ))
388
+ return parent->astOperand1 ()->tokAt (2 );
389
+ return nullptr ;
390
+ }
391
+
379
392
/* * Set token value for cast */
380
393
static void setTokenValueCast (Token *parent, const ValueType &valueType, const ValueFlow::Value &value, const Settings *settings);
381
394
@@ -446,13 +459,8 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
446
459
}
447
460
448
461
// cast..
449
- if (parent->str () == " (" && !parent->astOperand2 () && Token::Match (parent," ( %name%" )) {
450
- const ValueType &valueType = ValueType::parseDecl (parent->next (), settings);
451
- setTokenValueCast (parent, valueType, value, settings);
452
- }
453
-
454
- else if (parent->str () == " (" && parent->astOperand2 () && Token::Match (parent->astOperand1 (), " const_cast|dynamic_cast|reinterpret_cast|static_cast <" )) {
455
- const ValueType &valueType = ValueType::parseDecl (parent->astOperand1 ()->tokAt (2 ), settings);
462
+ if (const Token *castType = getCastTypeStartToken (parent)) {
463
+ const ValueType &valueType = ValueType::parseDecl (castType, settings);
456
464
setTokenValueCast (parent, valueType, value, settings);
457
465
}
458
466
@@ -4644,6 +4652,12 @@ static void valueFlowContainerAfterCondition(TokenList *tokenlist,
4644
4652
// TODO: Handle .size()
4645
4653
if (!isContainerEmpty (vartok))
4646
4654
return cond;
4655
+ const Token *parent = tok->astParent ();
4656
+ while (parent) {
4657
+ if (Token::Match (parent, " %comp%|!" ))
4658
+ return cond;
4659
+ parent = parent->astParent ();
4660
+ }
4647
4661
ValueFlow::Value value (tok, 0LL );
4648
4662
value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE;
4649
4663
cond.true_values .emplace_back (value);
0 commit comments