@@ -2341,8 +2341,12 @@ struct ValueFlowAnalyzer : Analyzer {
23412341 // Follow references
23422342 std::vector<ReferenceToken> refs = followAllReferences (tok);
23432343 const bool inconclusiveRefs = refs.size () != 1 ;
2344+ if (std::none_of (refs.begin (), refs.end (), [&](const ReferenceToken& ref) {
2345+ return tok == ref.token ;
2346+ }))
2347+ refs.push_back (ReferenceToken{tok, {}});
23442348 for (const ReferenceToken& ref:refs) {
2345- Action a = analyzeToken (ref.token , tok, d, inconclusiveRefs);
2349+ Action a = analyzeToken (ref.token , tok, d, inconclusiveRefs && ref. token != tok );
23462350 if (internalMatch (ref.token ))
23472351 a |= Action::Internal;
23482352 if (a != Action::None)
@@ -2944,29 +2948,34 @@ std::string lifetimeMessage(const Token *tok, const ValueFlow::Value *val, Error
29442948 const Token *tokvalue = val ? val->tokvalue : nullptr ;
29452949 const Variable *tokvar = tokvalue ? tokvalue->variable () : nullptr ;
29462950 const Token *vartok = tokvar ? tokvar->nameToken () : nullptr ;
2951+ const bool classVar = tokvar ? (!tokvar->isLocal () && !tokvar->isArgument () && !tokvar->isGlobal ()) : false ;
29472952 std::string type = lifetimeType (tok, val);
29482953 std::string msg = type;
29492954 if (vartok) {
2950- errorPath.emplace_back (vartok, " Variable created here." );
2955+ if (!classVar)
2956+ errorPath.emplace_back (vartok, " Variable created here." );
29512957 const Variable * var = vartok->variable ();
2958+ std::string submessage;
29522959 if (var) {
29532960 switch (val->lifetimeKind ) {
29542961 case ValueFlow::Value::LifetimeKind::SubObject:
29552962 case ValueFlow::Value::LifetimeKind::Object:
29562963 case ValueFlow::Value::LifetimeKind::Address:
29572964 if (type == " pointer" )
2958- msg + = " to local variable" ;
2965+ submessage = " to local variable" ;
29592966 else
2960- msg + = " that points to local variable" ;
2967+ submessage = " that points to local variable" ;
29612968 break ;
29622969 case ValueFlow::Value::LifetimeKind::Lambda:
2963- msg + = " that captures local variable" ;
2970+ submessage = " that captures local variable" ;
29642971 break ;
29652972 case ValueFlow::Value::LifetimeKind::Iterator:
2966- msg + = " to local container" ;
2973+ submessage = " to local container" ;
29672974 break ;
29682975 }
2969- msg += " '" + var->name () + " '" ;
2976+ if (classVar)
2977+ submessage.replace (submessage.find (" local" ), 5 , " member" );
2978+ msg += submessage + " '" + var->name () + " '" ;
29702979 }
29712980 }
29722981 return msg;
0 commit comments