-
Notifications
You must be signed in to change notification settings - Fork 249
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
Implement Type is Type
#782
Conversation
Relevant lines pasted from the grammar: ```c //G is-as-expression: //G prefix-expression //G is-as-expression is-value-constraint //GTODO type-id is-type-constraint ``` A *prefix-expression* can be an *unqualified-id*, which can also be a *type-id*. So when the latter is implemented, it would break any code using `identifier is` to test an expression. I understand the usual way of disambiguating is to require parens, so I have done that here to fix 5 `regression_tests`.
auto is() -> std::false_type { return {}; } | ||
|
||
template <typename X, typename C> | ||
requires std::same_as<X, C> || std::derived_from<X,C> |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I was wrong.
std::same_as
can be true
for non-class types,
whereas std::derived_from
can only be true
for classes.
Co-authored-by: Johel Ernesto Guerrero Peña <[email protected]> Signed-off-by: Nick Treleaven <[email protected]>
What about the alternative grammar? |
If this implements #358 (comment), |
Hi! Sorry it took me so long to get to this one. I'm going to close it as probably-dated now, but if you want to pursue it please reopen and refresh. Thanks again, and sorry again for the lag. |
This supplants #759. The same rationale applies for requiring
(identifier) is
to test an expression, see that PR for details. I added a diagnostic foridentifier is expr
whereexpr
is not a type-id, becauseType is expr
is not valid - instead it will suggest using(identifier) is
.cpp2util.h
changes are taken from #701 by @filipsajdak. That makesstd::runtime_error is std::exception
true, which seems correct, although I think that is not mentioned in P2392.I had to add a
speculative
parameter toparser::type_id()
which istrue
when there might not be a type (but an expression instead). This avoids an error forptr*
which is parsed as a postfix-expression from prefix-expression from is-as-expression.