cpp-object-lifetime
Installation
SKILL.md
C++ Object Lifetime
Use this skill when C++ code creates, stores, passes, captures, or returns a pointer, reference, view, iterator, or callback whose validity depends on another object's lifetime, and that dependency is not enforced by construction.
The goal is to make every lifetime dependency explicit: who owns the storage, how long the borrower may use it, and which operations invalidate it.
UTILITY SKILL. INVOKES: read-only file access for supplied targets; no other tools or skills. FOR SINGLE OPERATIONS: use for focused lifetime review, ownership design, invalidation analysis, or test planning.
Scope
- Use this skill for dangling pointers/references, iterator and reference invalidation, view types (
string_view,span,initializer_list, ranges) escaping their owner, temporaries bound to references, lambda capture lifetime, use-after-move, use-after-free, double-free, returning references to locals, and ownership-boundary design (unique_ptr,shared_ptr,weak_ptr, raw pointers, references). - Apply it to API signatures (parameter and return lifetime contracts), data members that borrow, callback registration, container mutation during iteration, and cross-thread object handoff where the lifetime question is who-outlives-whom.
- Keep the review centered on lifetime and ownership. Treat data-race and synchronization questions as residual context unless the race is itself a lifetime bug (object destroyed while another thread uses it).
DO NOT USE FOR:
- Coroutine frame, promise, or awaiter lifetime mechanics; algorithmic or style review with no lifetime dependency; build/link errors; pure performance tuning.
- Interpreting sanitizer reports when the task is triage of tool output rather than reasoning about ownership in code under review.