diff --git a/lib/token.cpp b/lib/token.cpp index f25e453c8..081c591a2 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -1773,7 +1773,8 @@ void Token::printValueFlow(bool xml, std::ostream &out) const out << "end=" << value.intvalue; break; case ValueFlow::Value::ValueType::LIFETIME: - out << "lifetime=" << "(" << value.tokvalue->expressionString() << ")"; + out << "lifetime[" << ValueFlow::Value::toString(value.lifetimeKind) << "]=(" + << value.tokvalue->expressionString() << ")"; break; } if (value.indirect > 0) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 148d02fc2..132336742 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -6916,6 +6916,22 @@ const char* ValueFlow::Value::toString(MoveKind moveKind) return ""; } +const char* ValueFlow::Value::toString(LifetimeKind lifetimeKind) +{ + switch (lifetimeKind) { + case LifetimeKind::Object: + return "Object"; + case LifetimeKind::SubObject: + return "SubObject"; + case LifetimeKind::Lambda: + return "Lambda"; + case LifetimeKind::Iterator: + return "Iterator"; + case LifetimeKind::Address: + return "Address"; + } + return ""; +} const ValueFlow::Value *ValueFlow::valueFlowConstantFoldAST(Token *expr, const Settings *settings) { diff --git a/lib/valueflow.h b/lib/valueflow.h index c655dcfc9..38d53ae4c 100644 --- a/lib/valueflow.h +++ b/lib/valueflow.h @@ -323,11 +323,23 @@ namespace ValueFlow { /** int value before implicit truncation */ long long wideintvalue; - enum class LifetimeKind {Object, SubObject, Lambda, Iterator, Address} lifetimeKind; + enum class LifetimeKind { + // Pointer points to a member of lifetime + Object, + // A member of object points to the lifetime + SubObject, + // Lambda has captured lifetime(similiar to SubObject) + Lambda, + // Iterator points to the lifetime of a container(similiar to Object) + Iterator, + // A pointer that holds the address of the lifetime + Address + } lifetimeKind; enum class LifetimeScope { Local, Argument, SubFunction } lifetimeScope; static const char* toString(MoveKind moveKind); + static const char* toString(LifetimeKind lifetimeKind); /** How known is this value */ enum class ValueKind {