Skip to content

Account for callback-result construction in pfn monadic noexcept - #460

Merged
Bronek merged 4 commits into
mainfrom
bronek/fix_noexcept_pfn
Oct 17, 2026
Merged

Bronek merged 4 commits into
mainfrom
bronek/fix_noexcept_pfn

Conversation

@Bronek

@Bronek Bronek commented Oct 17, 2026

Copy link
Copy Markdown
Member

A non-throwing callback can return an optional or expected by reference while copying or moving that result throws. The monadic operation previously overlooked that construction in its exception specification and could terminate instead of propagating the exception.

Account for result construction in and_then and or_else for owning and reference pfn::optional and both pfn::expected specializations. Use is_nothrow_invocable_r while retaining the existing checks for constructing the unchanged alternative. Preserve guaranteed copy elision for immovable prvalues, the draft's constraints, and invalid-callback diagnostics.

Addresses the pfn portion of #436. No include/fn files are changed; the fn wrapper fixes remain separate work. Document that remaining difference and exclude these new regressions from the shared suite's fn instantiations.

Validation:

  • Full GCC and Clang builds with libstdc++: 89/89 CTests passed on each.
  • C++23 and C++26 standard-library validation translation units compiled for optional and expected on both compilers.
  • Regressions cover throwing copies and moves, source and result cv/ref categories, non-throwing controls, and immovable prvalues. They fail against the preceding implementation.
  • Claude reviewed the fixes; test-portability and documentation feedback is incorporated. Pre-commit checks passed.

Assisted-by: Codex:gpt-6

Include copying or moving a reference-returned optional in and_then and
or_else exception specifications. Preserve guaranteed elision for prvalue
results and the draft's constraints and hard-error behavior.

Cover result and source cv/ref categories, exception propagation, and
immovable prvalues. Keep the new regressions out of the fn wrapper suite,
whose exception specifications are separate work.

Assisted-by: Codex:gpt-6
Include result copying or moving in and_then and or_else while retaining
the unchanged-side construction checks. Preserve guaranteed elision for
prvalue results and the draft's constraints and hard-error behavior.

Test all source cv/ref categories, reference-result copies and moves,
exception propagation, and immovable prvalues against pfn and std.

Assisted-by: Codex:gpt-6
Include result copying or moving in and_then and or_else. Keep the error
construction check on and_then and preserve guaranteed elision for
prvalues without adding constraints.

Exercise the same source and result cv/ref matrix as the object
specialization, including exception propagation and immovable results.
Guard constructor-noexcept extension assertions in std validation.

Assisted-by: Codex:gpt-6
@codecov

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@augmentcode

augmentcode Bot commented Oct 17, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: Corrects callback-result handling in pfn monadic exception specifications.

  • Updates and_then and or_else to use is_nothrow_invocable_r.
  • Covers owning and reference optional specializations.
  • Covers object and void expected specializations.
  • Allows throwing copies or moves of reference-returned results to propagate rather than terminate.
  • Retains checks for constructing unchanged values and errors.
  • Preserves guaranteed copy elision for immovable prvalue results.
  • Leaves participation constraints and invalid-callback diagnostics unchanged.
  • Adds runtime and constexpr regressions for cv/ref categories, throwing construction, and non-throwing controls.
  • Documents the remaining fn wrapper issue (and_then overlooks the copy when a callback returns a carrier by reference #436) and excludes these regressions from its shared-suite instantiations.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

MSVC 19.44 miscompiles negation of an enclosing boolean template
parameter across generic-lambda instantiations. Compare has_value()
directly with Recover using !=, preserving the assertions.

A standalone reproducer fails without libfn or Catch2. The affected
helper reproduces all 32 assertion failures on Godbolt MSVC in /Od and
/O2; both configurations pass with this change. Rebuilt GCC and Clang
expected suites also pass.

Assisted-by: Codex:gpt-6
@sonarqubecloud

Copy link
Copy Markdown

@Bronek
Bronek merged commit 96a5132 into main Oct 17, 2026
59 checks passed
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.

1 participant