Skip to content

Commit d740a83

Browse files
committed
wording: store the error as unexpected<E> in expected<T&, E>
An "as-if" exposition of the error as a union member E unex cannot represent the documented behavior: when E is an lvalue reference, E& is not a permissible union member. Specify the error member as unexpected<E> instead, which holds a pointer via unexpected<E&> for a reference E, and route error access through unex.error(). Update the dependent member descriptions (copy ctor, unexpect_t effects, error(), rebinding assignment) to match, and add a General paragraph stating why. Verified: build clean at 93 pages; stripped diff vs expected-base.tex still removes exactly 3 lines (all in the relaxation edits, none here).
1 parent 9ba9471 commit d740a83

1 file changed

Lines changed: 27 additions & 19 deletions

File tree

papers/expected-new.tex

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2988,23 +2988,27 @@
29882988
friend constexpr bool operator==(const expected&, const unexpected<E2>&);
29892989

29902990
private:
2991-
bool @\exposid{has_val}@; // \expos
2991+
bool @\exposid{has_val}@; // \expos
29922992
union {
2993-
T* @\exposid{val}@; // \expos
2994-
E @\exposid{unex}@; // \expos
2993+
T* @\exposid{val}@; // \expos
2994+
unexpected<E> @\exposid{unex}@; // \expos
29952995
};
29962996
};
29972997
\end{codeblock}
29982998

29992999
\pnum
3000-
Any object of type \tcode{expected<T\&, E>} either
3001-
represents a reference to an object of type \tcode{T}, or
3002-
contains a value of type \tcode{E} nested within\iref{intro.object} it.
3003-
Member \exposid{has_val} indicates whether the \tcode{expected<T\&, E>} object
3004-
represents a reference.
3005-
When an \tcode{expected<T\&, E>} object represents a reference,
3006-
member \exposid{val} points to the referenced object,
3007-
which is not owned by the \tcode{expected} object.
3000+
An object of type \tcode{expected<T\&, E>} either represents a reference to an
3001+
object of type \tcode{T}, or holds an error.
3002+
Member \exposid{has_val} indicates whether the object represents a reference.
3003+
When it represents a reference, member \exposid{val} points to the referenced
3004+
object, which is not owned by the \tcode{expected} object.
3005+
Otherwise, the error is \tcode{\exposid{unex}.error()}.
3006+
3007+
\pnum
3008+
The error is held as an \tcode{unexpected<E>}, and not as an \tcode{E}, so that
3009+
\tcode{E} can be an lvalue reference type: an \tcode{E\&} cannot be a union
3010+
member, whereas \tcode{unexpected<E\&>} holds a pointer to an external
3011+
object\iref{expected.un.ref}.
30083012

30093013
\pnum
30103014
A program that instantiates the definition of
@@ -3030,8 +3034,8 @@
30303034
\effects
30313035
If \tcode{rhs.has_value()} is \tcode{true}, initializes \exposid{val} with
30323036
\tcode{rhs.\exposid{val}}, so that \tcode{*this} and \tcode{rhs} refer to the
3033-
same object; otherwise, initializes \exposid{unex} with the error of
3034-
\tcode{rhs}.
3037+
same object; otherwise, initializes \exposid{unex} with
3038+
\tcode{rhs.\exposid{unex}}.
30353039

30363040
\pnum
30373041
\ensures
@@ -3162,7 +3166,10 @@
31623166

31633167
\pnum
31643168
\effects
3165-
Initializes \exposid{unex} with the given arguments.
3169+
Direct-non-list-initializes \exposid{unex} with \tcode{in_place} and
3170+
\tcode{std::forward<Args>(args)...} (respectively, \tcode{in_place},
3171+
\tcode{il}, and \tcode{std::forward<Args>(args)...}), so that the error
3172+
\tcode{\exposid{unex}.error()} is constructed from those arguments.
31663173
\tcode{has_value()} is \tcode{false}.
31673174
\end{itemdescr}
31683175

@@ -3258,9 +3265,10 @@
32583265

32593266
\pnum
32603267
\effects
3261-
Makes \tcode{*this} hold the error of \tcode{e}. When \tcode{E} is a reference
3262-
type, \exposid{unex} is made to refer to the same object as \tcode{e.error()};
3263-
the previously referenced object, if any, is not modified.
3268+
Makes \tcode{*this} hold the error of \tcode{e}, reinitializing \exposid{unex}
3269+
from \tcode{e} rather than assigning through it. When \tcode{E} is a reference
3270+
type, \tcode{\exposid{unex}.error()} thereafter refers to the same object as
3271+
\tcode{e.error()}; the previously referenced object, if any, is not modified.
32643272

32653273
\pnum
32663274
\returns
@@ -3402,8 +3410,8 @@
34023410

34033411
\pnum
34043412
\returns
3405-
A reference to the error, as for the primary template
3406-
(\ref{expected.object.obs}).
3413+
\tcode{\exposid{unex}.error()}, with the \tcode{const} and reference
3414+
qualification of the selected overload.
34073415
\end{itemdescr}
34083416

34093417
\indexlibrarymember{value_or}{expected}%

0 commit comments

Comments
 (0)