Compute a real noexcept for the sum, pack and choice surface#300
Merged
Conversation
This was referenced Jul 13, 2026
🤖 Augment PR SummarySummary: This PR makes the public Changes:
Technical Notes: The nothrow computation composes across pack/sum dispatch (runtime choice means “all alternatives must be nothrow”). It also accounts for brace-vs-paren initialization differences and guarded traits where 🤖 Was this summary useful? React with 👍 or 👎 |
54e67e6 to
dbd8898
Compare
The dispatch machinery promised `noexcept` unconditionally while invoking user
callbacks and constructing user types, so a throwing callback or a throwing copy
called `std::terminate` - and since the specification also read `noexcept == true`,
callers could not even detect the hazard by asking. The constructors were wrong the
other way: carrying no specifier at all, they under-promised, so `sum<int>{42}` was
`noexcept(false)`.
`is_nothrow_invocable` / `is_nothrow_invocable_r` (stubbed `false` until now) are the
foundation, and are computed by asking the invoke chain itself, which grows the
specification it was missing. That composes: a pack answers for the call over its
elements, a sum for the call over every alternative - one throwing alternative makes
the whole dispatch throwing, since which one runs is a run-time choice. The recursion
terminates because each step strictly reduces the number of pack/sum operands.
On top of that: the constructors weigh what they construct and relocate, `append`
weighs the element built and every element moved into the new pack, `operator==`
weighs the alternatives' own comparisons, and `choice` stops over-promising where
`optional` and `expected` never did.
Two traps worth naming. A `noexcept`-specifier is an ordinary constant expression,
not a requires-clause: both operands of its `||` must be well-formed, so "this
alternative is not compared, and need not be comparable" has to be a guarded trait
rather than a disjunction. And an explicit `noexcept` on a defaulted copy/move that
disagrees with the implicit specification deletes it - `choice`'s had to drop theirs
once `sum`'s became conditional.
Closes #45
Closes #280
Assisted-by: Claude:claude-opus-4-8[1m]
7dcd970 to
48fcd2f
Compare
Member
Author
|
augment review |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



The dispatch machinery promised
noexceptunconditionally while invoking user callbacks and constructing user types, so a throwing callback or a throwing copy calledstd::terminate- and since the specification also readnoexcept == true, callers could not even detect the hazard by asking. The constructors were wrong the other way: carrying no specifier at all, they under-promised, sosum<int>{42}wasnoexcept(false).is_nothrow_invocable/is_nothrow_invocable_r(stubbedfalseuntil now) are the foundation, and are computed by asking the invoke chain itself, which grows the specification it was missing. That composes: a pack answers for the call over its elements, a sum for the call over every alternative - one throwing alternative makes the whole dispatch throwing, since which one runs is a run-time choice. The recursion terminates because each step strictly reduces the number of pack/sum operands.On top of that: the constructors weigh what they construct and relocate,
appendweighs the element built and every element moved into the new pack,operator==weighs the alternatives' own comparisons, andchoicestops over-promising whereoptionalandexpectednever did.Two traps worth naming. A
noexcept-specifier is an ordinary constant expression, not a requires-clause: both operands of its||must be well-formed, so "this alternative is not compared, and need not be comparable" has to be a guarded trait rather than a disjunction. And an explicitnoexcepton a defaulted copy/move that disagrees with the implicit specification deletes it -choice's had to drop theirs oncesum's became conditional.Closes #45
Closes #280
Stack: P6 of 13 — the release-0.1 bugfix queue, merging bottom-up into
main. Based on #299 and to be retargeted tomainonce it merges; the diff shows only this PR's commits. Every stack boundary was validated with a gcc build and the full test suite on top ofmain, and the aggregate branch ran the full CI matrix green (#289).