-
Notifications
You must be signed in to change notification settings - Fork 14
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
Specify and implement function subtyping. #57
Comments
The fix for this requires a kind of function subtyping. The call function isn't aware of the static lifetime constraint on T. It would need to specify When specializing class templates the lifetime arguments of the template arguments are factored out and appended as lifetime arguments of the specialization. A similar thing has to be done here. That should make the type of the rhs the same as the type of the lhs. |
Class template specializations where template parameters are lifetime binders (at least in the T+ variety) are themselves lifetime binders. This allows us to hoist out the lifetime arguments of the template arguments and make them lifetime arguments of the specialization. Currently, function types are not lifetime binders. This probably has to change to support subtyping. I don't know about stripping of lifetime arguments in this case. template<typename T>
void call(T);
int main() {
void(*pf)(int^/static) = addr call<int^/static>;
}
cannot convert lvalue int^/SCC-0(int^/SCC-0) to int^/static(*)(int^/static) If the rhs can be converted to the lhs type by subtyping, can you still strip the lifetime arguments off the rhs? That would imply you can also strip them off the lhs. I see three possible ways to treat this subtyping:
Option 3 seems most desirable. Placeholder lifetimes in the template arguments would create no additional constraints. But I don't know yet how to deal with non-static lifetimes, such as named lifetimes. If I used the actual named lifetime for defining a function type, incorporating the hash of its lifetime_param_t*, how would canonicalization work? That would seemingly take us back to the start of the problem: we've erased the specific lifetime argument and made a type that's more generic than the one requested by the user. |
#feature on safety
template<typename T>
T call(T);
int^(*pf)(int^) = call<int^>; build_sep_19_2024-1 implements lifetime normalization on function type declarators, which allows this assignment to work. This should open the door for real subtyping during standard conversions between function types. |
See: |
The text was updated successfully, but these errors were encountered: