Skip to content

Pass buffer sequences by value in read() and write()#278

Merged
mvandeberg merged 1 commit into
cppalliance:developfrom
mvandeberg:pr/263-buffers-by-value
May 12, 2026
Merged

Pass buffer sequences by value in read() and write()#278
mvandeberg merged 1 commit into
cppalliance:developfrom
mvandeberg:pr/263-buffers-by-value

Conversation

@mvandeberg
Copy link
Copy Markdown
Contributor

The free-function read and write overloads previously bound the buffer sequence by const reference. With lazy coroutines this dangles: the returned io_task can be stored past the full-expression that created the sequence, by which point the const reference points at a destroyed temporary. Switch both to by-value so the sequence lives in the coroutine frame.

Update the ReadStream/WriteStream concept docstrings to list only the by-value signature as conforming and document the std::views::all caller-side workaround for expensive owning sequences. Append a Resolution section to doc/buffers-passing-rationale.md recording the decision and why both const& and && fail under lazy coroutines.

Add regression tests that store the returned awaitable past a temporary buffer sequence; verified to trip ASan stack-use-after-scope with the previous signatures and to pass cleanly with by-value.

Resolves #263.

@cppalliance-bot
Copy link
Copy Markdown

cppalliance-bot commented May 12, 2026

An automated preview of the documentation is available at https://278.capy.prtest3.cppalliance.org/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-05-12 19:01:55 UTC

@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.37%. Comparing base (ac63112) to head (d0bfb66).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #278   +/-   ##
========================================
  Coverage    92.37%   92.37%           
========================================
  Files          168      168           
  Lines         9414     9414           
========================================
  Hits          8696     8696           
  Misses         718      718           
Flag Coverage Δ
linux 92.36% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
include/boost/capy/read.hpp 100.00% <ø> (ø)
include/boost/capy/write.hpp 100.00% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ac63112...d0bfb66. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cppalliance-bot
Copy link
Copy Markdown

cppalliance-bot commented May 12, 2026

GCOVR code coverage report https://278.capy.prtest3.cppalliance.org/gcovr/index.html
LCOV code coverage report https://278.capy.prtest3.cppalliance.org/genhtml/index.html
Coverage Diff Report https://278.capy.prtest3.cppalliance.org/diff-report/index.html

Build time: 2026-05-12 19:17:01 UTC

The free-function `read` and `write` overloads previously bound the
buffer sequence by const reference. With lazy coroutines this dangles:
the returned `io_task` can be stored past the full-expression that
created the sequence, by which point the const reference points at a
destroyed temporary. Switch both to by-value so the sequence lives in
the coroutine frame.

Update the ReadStream/WriteStream concept docstrings to list only the
by-value signature as conforming and document the `std::views::all`
caller-side workaround for expensive owning sequences. Append a
Resolution section to doc/buffers-passing-rationale.md recording the
decision and why both `const&` and `&&` fail under lazy coroutines.

Add regression tests that store the returned awaitable past a
temporary buffer sequence; verified to trip ASan stack-use-after-scope
with the previous signatures and to pass cleanly with by-value.

Resolves cppalliance#263.
@mvandeberg mvandeberg force-pushed the pr/263-buffers-by-value branch from bffa443 to d0bfb66 Compare May 12, 2026 18:55
@mvandeberg mvandeberg merged commit 78ceedf into cppalliance:develop May 12, 2026
39 checks passed
@mvandeberg mvandeberg deleted the pr/263-buffers-by-value branch May 12, 2026 20:48
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.

Buffer sequence ownership should be clarified

2 participants