write_env: No Evaluated Context for Environment Type #1654
Merged
+71
−4
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 get_env implementation for stdexec::write_env is supplied via a lambda. Prior to this commit that lambda relied on automatic return type deduction. When a function relies on automatic return type deduction the compiler must evaluate the body thereof to determine the type returned thereby. A consequence of the aforegoing formulation is that if any statement in the body of the lambda directly or transitively relied on the completeness of an incomplete type compilation would fail.
The above might seem normal and non-problematic until one considers that it is fairly normal in C++ code to compute (and rely upon) types and other properties of functions long before any bona fide evaluation of that function occurs. This motivates the distinction between evaluated and unevaluated contexts. However as a consequence of the preceding paragraph the previous implementation of get_env meant that when code relied upon the return type thereof in an unevaluated context the context became an evaluated context in the body of get_env (and transitively through all statements therein).
The newly-added unit test highlights this. With the previous implementation of get_env (which uses automatic return type deduction) compilation fails. With the new implementation of get_env (which provides an explicit return type) compilation succeeds.