Repository navigation
Update to specgen 0.58.0, and close the reference gaps it and optional's changes exposed - #126
Merged
Merged
Conversation
The checked-in wording was generated by an older specgen, of the 0.47
line as far as the plan records, and `make wording-check` no longer
passed against it with any current specgen. Regenerated with 0.58.0
(0d034bc); `--validate` reports the same 107 notes as 0.56.2 and nothing
above a note.
What moved, by the specgen change that moved it:
- Code in item declarations and synopses wraps at the draft's 97
columns (specgen#446). Template heads short enough to share a line
with their declaration in a synopsis now do, as the draft writes
`template<class G = E> constexpr E error_or(G&&) const &;`.
- BEMAN_EXPECTED_CONSTEXPR_EXCEPTION no longer appears in the
bad_expected_access synopses (specgen#349).
- The deduction guide for unexpected is in its class synopsis.
- A body-local alias named by the assertions that give a derived
Mandates is introduced by a derived "Let U be ..." paragraph
(specgen#442), 21 of them, all in the monadic operations and in
[expected.ref].
- Definitions with nothing to contribute no longer leave a stray blank
line (specgen#436).
One regression comes with it: the derived Constraints of the primary
template's two error_or overloads now read
`typename expected<T, E>::error_value_type` where they read
`\exposid{error-value-type}`. The next commit works around it.
Against the working draft at n5054, `make wording-gap` counts slightly
fewer change marks than 0.56.2 does on the same headers.
The out-of-class definitions of the primary template's error_or have to
qualify the alias, `typename expected<T, E>::error_value_type`, and
specgen 0.58.0 derives the Constraints from that requires-clause as
written: the qualified name is shown as source, not as
`\exposid{error-value-type}`. Older specgen showed the exposition-only
name.
An authored \constraints with the unqualified name replaces the derived
one. --validate cannot yet match the two spellings, so the run gains
four notes, each a derived conjunct "with no authored constraints
counterpart"; they are the same defect and will go when specgen
resolves the qualified name.
…rloads specgen 0.58 derives the draft's leading "Let U be ..." paragraph from a body-local alias that the Mandates assertions name. The alias in and_then's & body was spelled with T&, so the derived paragraph said `invoke_result_t<F, T&>` for an item that also covers the const& overload, while the docblock restated U in full twice, in the Mandates and in a trailing "where U is ...". The alias is now spelled `decltype((val_))` in both the & and const& bodies, which is the same type in each and is the draft's own spelling, so the derived paragraph reads exactly as [expected.object.monadic] does. The Mandates name U and use the draft's words; the trailing "where" clause is gone. --validate now matches the authored is_same_v conjunct with the derived one and reports one note fewer. This is the pattern for the other twenty "Let" items; only this group is converted here.
…TION specgen writes a specifier macro as its expansion in the translation unit it parses, and since specgen#377 it does so for a macro the header #undefs at the end, as bad_expected_access.hpp does. What remained was which expansion: the one the standard library specgen's Clang found, which here was the empty one, so nine declarations the draft marks constexpr lost it. SPECGEN_CLANG_ARGS now defines __cpp_lib_constexpr_exceptions as libstdc++ 16 does, so the wording shows constexpr on every machine. The macro appears 0 times in the wording. Against the draft at n5054, [expected.bad] goes from 1 / 3 marks to 1 / 0 (the parameter name left) and [expected.bad.void] from 8 / 8 to 8 / 0 (the `= default`s left).
implementation-extras decided that the wording shows the draft's declaration where the implementation declares more, and that nothing changes in the headers until specgen has a marker for it. specgen#385 added `\omit noexcept` and `\omit default`. `\omit noexcept` on the three constructors of unexpected, the default constructor of expected<T, E>, and the copy constructors and copy assignment operators of expected<T, E> and expected<void, E>: each has a conditional noexcept the draft does not, as [res.on.exception.handling] allows. `\omit default` on the six special members of bad_expected_access<void>, which the draft declares without defining. Against the draft at n5054: [expected.bad.void] has no marks, from 8 / 0; [expected.unexpected] 10 / 3, from 16 / 7, the rest parameter names, which #385 left out, a *see below* on swap and a reordering; [expected.expected] 142 / 105, from 153 / 109; [expected.void] 193 / 140, from 196 / 141. --validate is unchanged.
macro-specifiers and implementation-extras are done; the deduction guide and the section-prose order came with specgen alone. The two defects found are in the specgen-pin Log with what was done about each, and derived-let opens the question of how the monadic operations state U and G now that specgen derives the binding.
Carries derived-let through the monadic operations of all three classes, and value_or of expected<T&, E>, as the lvalue and_then of the primary template already was. The body aliases are spelled as the draft binds them where that is the same type: `decltype((val_))` and `decltype(std::move(val_))` for U in the primary template, and `decltype(error())` for G in the lvalue overloads of all three. In expected<T&, E>, U stays `T&`, which is right for every overload. The rvalue G aliases keep `E&&`: for a reference E, `decltype(std::move(error()))` is an rvalue reference where the call passes an lvalue, so the draft's spelling would name a different type. The authored Mandates name U and G, and every trailing "where U is" is gone. transform and transform_error named the result `expected<U2, E>` U, and the error type G2, which contradicted the derived binding; they now use the draft's U and G, with an authored "Let" for transform, whose assertions are not leading and so derive nothing. value_or names X. --validate reports 105 notes, from 110; none is new. Against the draft at n5054, [expected.expected] is 130 / 96, 45 / 60 marks, from 142 / 105, 45 / 62, and [expected.void] 161 / 128, 36 / 37, from 193 / 140, 36 / 39.
…ader draft-text-copies: a copy goes when the generated synopsis of its class matches the draft's. [expected.bad.void] now has no marks against the draft at n5054, so the comment block is a third copy that nothing checks. The [expected.bad] copy stays; that synopsis still names the constructor's parameter.
macro-expansion-args and derived-let are decided as recommended, and derived-let is carried out. specgen#487 and #488 are filed and in the requests table. draft-text-copies logs the [expected.bad.void] copy gone. rvalue-error-binding opens the one place the draft's spelling of G names a different type from the code's, for a reference E.
The rvalue G aliases left alone are twelve, four in each class, not four. The review's findings go in the question's Log: the paper's own design section already makes move-the-wrapper-then-access a guarantee, the code follows it, and 26 places in the wording do not.
The design sections were titled with serial numbers, (D1) to (D12), and two sentences referred to a decision by number. A reader of the paper has no list those numbers index. The titles now stand alone and the two sentences say what they mean without the number. The unmerged prose pass on expected-over-references-paper makes the same change to the titles; the wording here matches it.
…perations The wording said `std::move(error())` in 26 places: access, then move. For an object E that is the draft's text and means what it meant. For a reference E it marks as an rvalue an object that the expected does not own. Read as written, `error_or() &&` and `value() &&` would move out of the referent themselves, the rvalue `or_else` and `transform_error` would hand the callable an rvalue to it, and the rvalue `and_then` and `transform` would be constrained away or ill-formed. The code never did any of this: it moves the held unexpected<E> and then asks it for the error. The docblocks now say what the code does, `std::move(unex).error()`, the form the paper's design already requires and that `error() &&` already used. `unex` is the exposition-only unexpected<E> of all three classes, so the expression is E&& for an object E, as before, and E& for a reference E, for both `&&` and `const&&`. The twelve rvalue G aliases are spelled the same way, so the derived "Let G be ..." is exact for both overloads of its item, which `E&&` was not. The two assertions in `value() &&` follow, and no access-then-move is left in the code. No type changes.
…referenced error The guarantee was tested for the conversions only. These cover `error_or() &&` and `value() &&`, where the library itself initializes an object from the error, the rvalue `or_else` and `transform_error`, which must pass a referenced error to the callable as an lvalue, and the rvalue `and_then` and `transform`, which must rebind it. Each kind is paired with a case showing that an owned error is still moved.
…ex).error() The paper's design makes move-the-holder-then-access a guarantee, and its wording for the rvalue observers and monadic operations still carried the draft's `std::move(error())`, which for a reference E moves the referent. 22 places in [expected.object] and [expected.void] are marked as changed to `std::move(unex).error()`, the expression `error() &&` already returns; the one in [expected.ref] is inside the added clause and is replaced without a mark. This is the text the headers now generate.
Steve Downey's ruling, why it is not std::move(*this).error(), where unex is and is not in scope, and what is left: the same-type move members' spelling, and the paper's prose for the 22 new marks.
… forgotten Checked expected against the small changes P2988R12 and its follow-up issues made to optional outside [optional.ref]. Each names a place where a deduced or parameter type may now be a reference and the base wording or code assumed it was not. Copying an expected<T&, E> or an unexpected<E&> from a const rvalue of its own type was a hard error under gcc-16. The deleted "would bind a temporary" constructor template deduced the class itself and had no guard for that, so its constraint depended on itself. It now carries the enabled overload's guards. transform_error accepts a callable that returns an lvalue reference and returns expected<T, G&>, as transform already returned expected<U&, E>, and as optional<T>::transform returns optional<U&>. An rvalue reference result is still rejected; the four compile-fail tests now cover that case and are renamed for it. expected<T, E> and expected<void, E> assert that E, less any reference, is an object type, as expected<T&, E> and unexpected<E&> already did. Nothing that compiled is rejected: unexpected<E&> already refused a function type, after a less useful error. The docblocks, and so the generated wording, follow: - "valid value type" admits an lvalue reference to a non-array object type; - the transform docblocks have the draft's shape, with Mandates, and no longer name the in_place_t constructor, which expected<T&, E> deletes; - the move constructors and move assignment move rhs.unex, not rhs.error(); - value() Mandates test error-value-type, not E, and expected<T&, E> has them; - the deleted reference constructors are stated as optional states them: "This constructor is defined as deleted if ..."; - the synopsis declares unexpected<E&> and expected<T&, E>; - value() is freestanding-deleted in expected<T&, E>.
Against the working draft, in expected-new.tex: - "valid value type" admits an lvalue reference to a non-array object type, and the four Returns of transform say what val is for a reference U; - the move constructors and the move assignment move rhs.unex where the draft has std::move(rhs.error()), which for a reference E hands an rvalue to unexpected<E&>; - the Constraints of swap admit a reference E whatever its referent; - the Mandates of value() test remove_cv_t<remove_reference_t<E>>, since a trait on a reference E is vacuous; - a 23rd std::move(error()), in the Mandates of value() &&, which a \linebreak had hidden from the earlier search; - the synopsis declares unexpected<E&> and expected<T&, E>. In the added clauses: the deleted reference constructors are stated as optional states them, [expected.un.ref] requires an object type, and [expected.ref] gains Mandates for value() and marks it freestanding-deleted.
…ce result is The section on stealing covers the rvalue observers and monadic operations as well as conversions, and is retitled for that. It names the draft's std::move(error()) as access-then-move and std::move(unex).error() as its replacement. "Monadic operations are uniform" states that a callable returning an lvalue reference gives a reference expected, as for optional, and that the result can dangle, which is the callable's property and is left to the caller. A new short section says referents are non-array object types: optional<T&> admits arrays and functions and LWG4304 keeps that working, and this paper does not rewrite expected to follow without direction to do so.
…parison The decision that transform and transform_error yield a reference expected for a callable returning an lvalue reference, as decided by the optional precedent, with what the same comparison found and changed. The log of rvalue-error-binding gains the 23rd mark and the corrected scope of the rebinding paragraph, which covers the move assignment and not the two move constructors.
MSVC 19.52 rejects four out-of-line definitions in expected<T, E> with C2244 (bemanproject#127): the value constructor, the value assignment and the two error_or overloads. Each definition's requires-clause named the class or its error-value-type with different tokens from the in-class declaration. The two are only functionally equivalent, which [temp.over.link] makes ill-formed, no diagnostic required. Clang 18 rejects the same four and nothing else in the header, which gives a way to check this without MSVC. The constructor and the assignment now say expected<T, E> in the declaration too. error_or says remove_cv_t<remove_reference_t<E>> in both, as expected<void, E> and expected<T&, E> already did. Both spellings mean the same at class scope and at namespace scope, so neither relies on a leading requires-clause being looked up in the class, which no other definition in the header relies on either. Clang 18 goes from four errors in the header to none, in C++20, 23 and 26. Not verified with MSVC: there is no MSVC job in CI. The generated wording is unchanged.
The MSVC jobs beman.typeclass runs, on the same reusable workflows: the msvc-debug and msvc-release presets on windows-latest, and a build-and-test entry for the latest MSVC at C++23 with Debug, Release, MaxSan and the modules build. The two MSVC presets set CMAKE_CXX_STANDARD to 23, as typeclass's do. The root preset is C++20, and MSVC has reference_constructs_from_temporary only as the C++23 library trait. This is what would have caught bemanproject#127. Whether the rest of the library and its tests pass under MSVC is not known until these run.
The first MSVC run compiled everything and failed one test of the 708 it reached: "expected<T&,E&>: fully trivial — both sides are pointers". The library was not at fault. The name has an em dash, the only non-ASCII character in any test case name, and it did not survive the Windows command line that ctest passes it on, so Catch2 matched no test case and reported that none ran. ctest stops at the first failure, so the remaining 553 tests did not run.
…l tests
MSVC rejects expected<T, E&>(unexpect, {...}) on the deleted
initializer-list overload with C2280, "attempting to reference a deleted
function", which none of the three EXPECT patterns matched. Add the
alternative the other deleted-function compile-fail tests already carry.
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // NEGATIVE: expected<T&, E&> initializer-list error construction: E& cannot bind to the list | ||
| // EXPECT: "initializer-list error construction cannot bind a reference|use of deleted function|call to deleted" | ||
| // EXPECT: "initializer-list error construction cannot bind a reference|use of deleted function|call to deleted|attempting to reference" |
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
Suggested change
| // EXPECT: "initializer-list error construction cannot bind a reference|use of deleted function|call to deleted|attempting to reference" | |
| // EXPECT: "initializer-list error construction cannot bind a reference|use of deleted function|call to | |
| // deleted|attempting to reference" |
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // NEGATIVE: expected<T, E&> initializer-list error construction: E& cannot bind to the list | ||
| // EXPECT: "initializer-list error construction cannot bind a reference|use of deleted function|call to deleted" | ||
| // EXPECT: "initializer-list error construction cannot bind a reference|use of deleted function|call to deleted|attempting to reference" |
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
Suggested change
| // EXPECT: "initializer-list error construction cannot bind a reference|use of deleted function|call to deleted|attempting to reference" | |
| // EXPECT: "initializer-list error construction cannot bind a reference|use of deleted function|call to | |
| // deleted|attempting to reference" |
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // NEGATIVE: expected<void, E&> initializer-list error construction: E& cannot bind to the list | ||
| // EXPECT: "initializer-list error construction cannot bind a reference|use of deleted function|call to deleted" | ||
| // EXPECT: "initializer-list error construction cannot bind a reference|use of deleted function|call to deleted|attempting to reference" |
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
Suggested change
| // EXPECT: "initializer-list error construction cannot bind a reference|use of deleted function|call to deleted|attempting to reference" | |
| // EXPECT: "initializer-list error construction cannot bind a reference|use of deleted function|call to | |
| // deleted|attempting to reference" |
…lone Adding the alternative made each of the three EXPECT lines 136 columns. The limit is 119 and ReflowComments is on, so the pre-commit check rewrapped the comment, which would cut the pattern in two. The driver joins every EXPECT line of a file with "|", and other tests already use two lines for this, so the first line goes back to what it was and the new alternative gets a line of its own. The pattern the driver reads is unchanged.
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.
Three pieces of work, in the order the commits tell them.
specgen 0.58.0
The generated wording in
papers/wording/is regenerated with specgen 0.58.0, and uses what the new release offers:UandGfor the monadic operations from the body's own alias, as the draft does, so the authored "whereUis ..." text is gone.BEMAN_EXPECTED_CONSTEXPR_EXCEPTIONshows asconstexpr, and\omit noexcept/\omit defaultshow the draft's declarations where the library strengthens them.error_or's Constraints are authored so they nameerror-value-type.[expected.bad.void]synopsis is dropped from the header; that section now has no marks against the draft.Two specgen bugs found on the way are filed upstream: steve-downey/specgen#487 and steve-downey/specgen#488.
Rvalue access to a referenced error
The draft spells the error of an rvalue
expectedasstd::move(error()). That is access-then-move: harmless whileEcould not be a reference, and theboost::optional<T&>steal once it can. The wording and the code now move the holder and then ask it,std::move(unex).error(), which isE&&for an objectEandE&for a referenceE. This is 23 marked places inpapers/expected-new.tex, the docblocks, twelve aliases and two assertions in the code, and tests forerror_or() &&,value() &&and the rvalue monadic operations.The base templates, checked against optional
P2988R12 and its follow-up issues made a handful of small changes to
optionaloutside[optional.ref]. Each names a place where a type may now be a reference. Checking the same places inexpectedfound:expected<T&, E>orunexpected<E&>from a const rvalue of its own type failed under gcc-16: a deleted constructor template deduced the class itself and its constraint depended on itself. Fixed, with tests.expected<U&, E>fromtransformandexpected<T, G&>fromtransform_error, asoptional<T>::transformyieldsoptional<U&>. The code already did the first and rejected the second; the paper's wording had it the other way round. Four compile-fail tests that held the old rejection now cover an rvalue reference result, which is still ill-formed, and are renamed.std::move(rhs.error()), nowstd::move(rhs.unex)), the Constraints ofswap, and the Mandates ofvalue().[expected.syn]declares the two specializations, the deleted reference constructors are stated asoptionalstates them,value()is freestanding-deleted inexpected<T&, E>, andexpected<T, E>asserts that a referenceErefers to an object type instead of failing later with "function returning a function".A matrix of 400 converting constructions and assignments across the specializations and value categories showed no steal, no reference into a temporary source and no assign-through. The draft's
std::forward<UF>(*rhs)collapses correctly for a referenceU, soexpecteddid not need the fixoptional's converting constructors got.The paper
D4280 explains the rvalue change in a retitled section, "An rvalue
expectedmust not let its referent be stolen", says in "Monadic operations are uniform" what a reference result is and that it can dangle, and has a new short section saying referents are non-array object types:optional<T&>admits arrays and functions and LWG4304 keeps that working, and the paper does not rewriteexpectedto follow. The decision numbers are out of its section titles.Checks
1261 tests pass with gcc-16.
make wordingvalidates with 103 notes and no warnings,make wording-checkpasses, andpapers/D4280R0.pdfbuilds. The decisions are logged indocs/plan/specgen-catchup.mdunderderived-let,rvalue-error-bindingandreference-result-of-transform.