Skip to content
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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Implement Type is Type #782

wants to merge 10 commits into from

Conversation

ntrel
Copy link
Contributor

@ntrel ntrel commented Oct 25, 2023

This supplants #759. The same rationale applies for requiring (identifier) is to test an expression, see that PR for details. I added a diagnostic for identifier is expr where expr is not a type-id, because Type is expr is not valid - instead it will suggest using (identifier) is.

cpp2util.h changes are taken from #701 by @filipsajdak. That makes std::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 to parser::type_id() which is true when there might not be a type (but an expression instead). This avoids an error for ptr* which is parsed as a postfix-expression from prefix-expression from is-as-expression.

ntrel and others added 9 commits October 16, 2023 16:30
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.

Copy link
Contributor

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.

source/parse.h Outdated Show resolved Hide resolved
Co-authored-by: Johel Ernesto Guerrero Peña <[email protected]>
Signed-off-by: Nick Treleaven <[email protected]>
@JohelEGP
Copy link
Contributor

What about the alternative grammar?

@JohelEGP
Copy link
Contributor

I added a diagnostic for identifier is expr where expr is not a type-id, because Type is expr is not valid - instead it will suggest using (identifier) is.

If this implements #358 (comment),
please add "Closes #358" to the opening comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants