-
Notifications
You must be signed in to change notification settings - Fork 259
[BUG] forward
on non-deducible parameter is move
#572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
In my current use case, I don't care about
But that treats requires (std::is_same_v<CPP2_TYPEOF(q), quantity>) That ends up with this error:
What I want is this behavior from P2392's §2.1: So given appropriate I want
to respectively translate to
With the following two overloads, template <template <typename...> class C, typename T>
consteval auto is() -> bool {
if constexpr (requires(T t) { []<typename... Ts>(C<Ts...> const&) { }(t); }) {
return true;
}
return false;
}
template <typename T, typename U>
consteval auto is() -> bool {
return std::is_same_v<T, U>;
} |
An alternative expected result of This formulation does that (https://compiler-explorer.com/z/hq1W6PTMP): template<typename q_t, typename Number = typename decltype([]<typename Number>(const quantity<Number>&) { return std::type_identity<Number>{}; }(std::declval<q_t>()))::type> auto from(q_t&& q) -> void;
template<typename q_t, typename Number> auto from(q_t&& q) -> void { (void) (CPP2_FORWARD(q).number = Number()); } The error messages do leave a lot to be desired (uncomment the call with |
Actually, I do have an use case:
I call those on prvalues, so I didn't notice the parameters were rvalues and not forwarding. |
Thanks! I've read through the use cases a few times, and I think the part of this that is a feature extension can be deferred to the future. But I think the original ask was this:
If there's a better diagnostic we can emit for erroneous code, could we have a PR for that? Otherwise we can close this I think? Thanks! |
A PR would be trivial after #534 is fixed. |
The comments #572 (comment) and #572 (comment) Cppfront implements from P2481
What's missing in Cppfront from P2481 |
Title:
forward
on non-deducible parameter ismove
.Description:
I inadvertently wrote the function
from: <Number> (forward q: quantity<Number>)
,thinking that would make
q
a forwarding parameter for anyquantity
.Cppfront recognizes
q
's type as non-deducible,and doesn't make
q
a forwarding parameter.The end result is that the generated code is the same as using
move
instead offorward
.Minimal reproducer (https://cpp2.godbolt.org/z/qTnYan8f4):
Commands:
cppfront main.cpp2 clang++17 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -fsanitize=undefined -Werror=unused-result -I . main.cpp
Expected result: A diagnostic indicating that
q
can't be made a forwarding parameter.Actual result and error:
Cpp2 lowered to Cpp1:
See also:
typename
! #531The text was updated successfully, but these errors were encountered: