-
Notifications
You must be signed in to change notification settings - Fork 207
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
Add c++17 fold expression #234
Add c++17 fold expression #234
Conversation
be56c19
to
47367a4
Compare
Added call for reviewers on cdt-dev. If none are forthcoming we'll need a plan-B (me learning this area?) |
#include <iostream>
template<typename ... T>
void sum(T ... vals) {
std::cout << "Total = " << (... + vals) << std::endl;
}
int main() {
sum(1, 2, 3);
return 0;
} |
Yes this test actually depends on pack expansion fix #230 to calculate size of char array in the third argument. If #230 will get delayed I'll change this test to just use simple types to not stumble upon that composite access issue. |
Thanks, this turned out to be a bug in implementation - fixed and added a test for fold expression inside binary expression. |
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.
LGTM.
As the logic you implemented is not trivial (at least to me), it might be good to add some additional tests. E.g. there is no test for the parser part which checks if there are more than one folds. I don't know if you are aware, but you can launch the tests as coverage and you will get a report about which code lines are covered by tests.
However there is no requirement for having a certain test coverage.
One thing I noticed is that the parser does not complain about some errors, e.g.
template<typename ... T>
void sum(T const ... vals) {
auto foo = bar (...+vals);
}
or
template<typename ... T>
void sum(T const ... vals) {
...+vals;
}
Not sure if this intended, but I think it is okay, because the compiler will complain later.
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFoldExpression.java
Show resolved
Hide resolved
....eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
Outdated
Show resolved
Hide resolved
0affc7e
to
b25f204
Compare
I now fixed two cases that you indicated by limiting fold expression recognition to Looking back I might have started adding fold expression to parser in the wrong place (altering binary expression handling) but at the time changing the proper place (primary expression handling) looked too difficult for me. |
b25f204
to
9230cba
Compare
Rebased to master after #230 merged to resolve |
9230cba
to
44cab9a
Compare
I don't know if anyone else can comment/confirm that at the high level you have the addition in the correct place. This change is also large and needs a quick run through the IP team, quoted from eclipsefdn/eca check:
|
I'm sure this is mostly due to long lists of allowed fold expression operators )) Happy to assist if needed. |
The iplab entry is here https://gitlab.eclipse.org/eclipsefdn/emo-team/iplab/-/issues/6713 |
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.
This looks fine to me. Needs iplab resolved before it can be merged.
Thanks @i-garrison for the improvement and thanks @ddscharfe for reviewing.
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFoldExpression.java
Show resolved
Hide resolved
Hi @jonahgraham would you believe we can get this approved before next milestone deadline? I'm thinking about yet another bugfix, which is not critical though - the fold expression validity check is currently too permissive. This does not affect valid code and does not affect parsing of fold expression either, so I'm planning to submit the improvement later after this PR is hopefully merged. |
I hope so! My past experience of reviews of this type have been very quick. I have pinged the IP team too.
Fair enough, I hope that the IP process isn't too cumbersome. Once you have a track record of contributions then you can become a committer on the project, as a committer your changes don't need further IP reviews as the committer agreement handles that. |
The ipteam have completed their review and therefore I have merged this change. Thanks @i-garrison! |
Oops, I guess I should have rebased the PR before merging it, unfortunately this PR did not apply cleanly, it led to compilation errors:
I have created a revert PR here: #278 - but I will have a quick go fixing the error before I merge #278. |
PR eclipse-cdt#234 had a compilation error once it was rebased which wasn't identified until after it was rebased and merged to main causing build to fail. This PR is to fix that rebase error.
PR #234 had a compilation error once it was rebased which wasn't identified until after it was rebased and merged to main causing build to fail. This PR is to fix that rebase error.
No description provided.