Commit b8a2589
committed
asioexec::completion_token: Conversion From Mutable Lvalue to Rvalue
Asio operations frequently declare completion signatures which are
correct only if you ignore cv- and ref-qualification. That is to say an
operation might declare void(int) as its completion signature but in
actual fact complete with int& or const int& (rather than the expected
int&&).
asioexec::completion_token has tried to deal with the above since it was
initially added (35a3e31), however this
has not been without issue (8bb5b46).
The correct way to deal with the above issue (as reified by
8bb5b46) is to use a combination of:
- std::is_convertible_v, and
- std::reference_converts_from_temporary_v
To determine whether values should be forwarded through to the receiver
or first converted. Unfortunately compilers/standard libraries that
don't feature std::reference_converts_from_temporary_v are supported
hence this fallback from 8bb5b46:
(
// Just using is_base_of_v is insufficient because it always reports false for built-in types
(std::is_base_of_v<std::remove_cvref_t<T>, std::remove_cvref_t<U>>
|| std::is_same_v<std::remove_cvref_t<T>, std::remove_cvref_t<U>>)
&&
// The returned type must be at least as cv-qualified as the input type (it can be more cv-qualified)
at_least_as_qualified_v<std::remove_reference_t<T>, std::remove_reference_t<U>>
&& (
// Reference type must agree except...
(std::is_lvalue_reference_v<T> == std::is_lvalue_reference_v<T>) ||
// ...special rules for const& which allows rvalues to bind thereto
(std::is_lvalue_reference_v<T> && std::is_const_v<std::remove_reference_t<T>>) ))
Unfortunately there's a typo under the comment which reads "[r]eference
type must agree except:" Both sides of the equality comparison are std::
is_lvalue_reference_v<T> thereby rendering it tautological. This had the
effect of activating the overload constrained thereby in the case where:
- The destination type (T) is an rvalue reference, and
- The source type (U) is a mutable lvalue reference
Leading to a compiler error of the following form:
error: rvalue reference to type 'boost::system::error_code' cannot
bind to lvalue of type 'boost::system::error_code'
100 | return static_cast<U&&>(u);
| ^~~~~~~~~~~~~~~~~~~
Which is #1724 (which this commit addresses).
Added a reproducing test and fixed.1 parent 5ffee46 commit b8a2589
File tree
2 files changed
+16
-1
lines changed- include/asioexec
- test/asioexec
2 files changed
+16
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1018 | 1018 | | |
1019 | 1019 | | |
1020 | 1020 | | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
1021 | 1036 | | |
0 commit comments