Skip to content

docs(cpp): warn that an async future must not outlive its client#867

Merged
userFRM merged 2 commits into
mainfrom
fix/cpp-async-this-capture
Jun 17, 2026
Merged

docs(cpp): warn that an async future must not outlive its client#867
userFRM merged 2 commits into
mainfrom
fix/cpp-async-this-capture

Conversation

@userFRM

@userFRM userFRM commented Jun 17, 2026

Copy link
Copy Markdown
Owner

The std::future from a C++ <endpoint>_async companion borrows the object it was called on (it captures this for the deferred std::async task). On the transient view returned by client.historical(), that view is destroyed at the end of the statement, so storing the future and calling get() later reads a dangling object (UB under ASan). Adds a \warning to every generated _async method documenting the standard std::async lifetime contract: call on a named HistoricalClient or chain the result. HistoricalClient (named, owning) was always safe.

🤖 Generated with Claude Code

The std::future returned by an <endpoint>_async companion borrows the
object it was called on. On the transient view from client.historical()
the view is destroyed at the end of the statement, so storing the future
and calling get() later reads a dangling object. Document the lifetime
contract on every generated _async method: call on a named
HistoricalClient or chain the result, never store the future from the
temporary historical() view.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@userFRM userFRM enabled auto-merge (squash) June 17, 2026 16:18
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@userFRM userFRM merged commit f6690bb into main Jun 17, 2026
44 checks passed
@userFRM userFRM deleted the fix/cpp-async-this-capture branch June 17, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants