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
[C++] Support requires-clause in more places #10286
Conversation
b41aa75
to
c1dce07
Compare
Note: I made some major changes to this PR to support a lot of additional things. As it is currently implemented, it does not prohibit requires clauses on concepts even though those are disallowed by C++. But I don't think that is a problem. Note: I noticed that there is support for non-standard concept introduction syntax, which I guess was part of an earlier concepts proposal. Should that be removed since it is not supported by C++? |
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.
Thanks for the PR. There are a number of structural changes to the code, and you list multiple changes. Please split it up into multiple commits to make it easier to review.
It would be nice to not allow it, unless it is really cumbersome to disallow.
They were indeed implemented during the Concepts TS time-frame. If they are in the way of implementing new things we should deprecate them, otherwise I see no harm in letting them be. |
type
, class
, 'member' declarations
Thanks for reviewing this change. I have split it up into multiple commits, and added a check to prevent a requires-clause on concepts. |
Previously a C++20 requires-clause was only supported on `function` declarations. However, the C++ standard allows a require-clause on class/union templates, alias templates, and variable templates, and also allows a requires clause after each template parameter list, not just the final one. This moves the requiresClause to be a property of `ASTTemplateParams` rather than `ASTDeclaration` to better match the C++ grammar and allows requires clauses in many places that are supported by C++20 but were not previously allowed by Sphinx, namely: - On class templates, alias templates, and variable templates - After each template parameter list, not just the last one. - After the template parameter list in template template parameters. When encoding the id, the requires clause of the last template parameter list is treated specially in order to preserve compatibility with existing v4 ids.
@jakobandersen Please let me know if there is anything I can do to help make progress with this and my other C++ PRs. Thanks! |
Is this really needed? As currently only the clause being ID-encoded is allowed, then all currently allowed declarations will have the same ID afterwards anyway. Or am I missing something? |
Previously, the requires clause was encoded after the template parameter list, so with a requires clause after the last template parameter list we would have:
if we didn't special case requires clauses on the last template parameter list, it would instead be:
|
I didn't see anything in the Itanium ABI regarding requires clauses --- not sure if you just invented a convention for them or if you used a convention defined elsewhere. With this change, I just used a convention that seemed to make sense. |
@jakobandersen Should we move this to 5.x, or is it nearly ready to be merged for 5.1? A |
I won't have time to properly dig back into it before the weekend, so please go ahead with the release and move this to 5.2. |
Indeed, good catch. |
Right, to my understanding it hasn't been updated officially yet, so this is just something I cooked up, and your changes are fine. |
C++, improve requires clause support (#10286 update)
I have rebased and updated this PR and merged it as #10703. Thanks again for your nice work. |
Feature or Bugfix
Purpose
Previously a C++20 requires-clause was only supported on
function
declarations. However, the C++ standard allows a require-clause on
class/union templates, alias templates, and variable templates, and
also allows a requires clause after each template parameter list, not
just the final one.
This moves the requiresClause to be a property of
ASTTemplateParams
rather than
ASTDeclaration
to better match the C++ grammar andallows requires clauses in many places that are supported by C++20 but
were not previously allowed by Sphinx, namely:
On class/union templates, alias templates, and variable templates
After each template parameter list, not just the last one.
After the template parameter list in template template parameters.
Additionally:
This adds support for template parameters on unions.
This adds support for trailing requires clauses on functions without
a template prefix. This is allowed by C++20 for non-template members
of class templates.
When encoding the id, the requires clause of the last template
parameter list is treated specially in order to preserve compatibility
with existing v4 ids.