-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Does the return of a template function have template phase? #3477
Comments
My initial idea here is that the answer should be "no", but maybe even more than suggested above: maybe it should be an error to declare a function with a return type that is dependent on a template parameter? And to make the examples work above, the declaration would have to explicitly make its return type itself a template -- I could imagine many syntaxes here, for example The advantage I could see here is avoiding surprising or subtle dependence on a template, especially in functions that use a mixture of checked and template parameters and intend to have the return type only involve the checked ones. But maybe there are disadvantages here that I'm not seeing that make it important to do this automatically? Either way, once the return type is a template (implicitly or explicitly), I would propagate that to the type of the call expression but not to something like To try to illustrate with examples:
|
An alternative to consider: the type of the return value has the same phase as the return type expression. So if it is dependent on a template parameter, it has template phase. Motivation for this approach includes (a) it is a simple rule consistent with our rules for template phase elsewhere in the language, (b) it allows constructs that require template phase, and (c) if the caller doesn't want a template phase value, the caller can then convert to symbolic phase using a |
It makes sense, but I think I still lean towards requiring the signature of the function to explicitly opt into it's return type having template phase. Inferring that from how the |
I meant that it would be determined by the return type expression (after the |
Summary of issue:
#2153 does not address whether the return type of a template function has template phase
Details:
Interesting examples:
The text was updated successfully, but these errors were encountered: