-
Notifications
You must be signed in to change notification settings - Fork 258
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
[BUG] for
loop don't allow several assignments in next
#448
Labels
bug
Something isn't working
Comments
Temporary workaround was found
First attempt``` main: () = { a:=0; b:=0; l := :() = { a&$*++; b&$*++; }; for "abc" next l() do (c) { std::cout << c << a << b << '\n'; } } ``` |
The example should be written like this: main: () = {
(copy a: = 0, copy b: = 0)
for "abc" next (a++, b++) do (i) {
std::cout << i << a << b << '\n';
}
} Cpp2 generates this: auto main() -> int{
{
auto a = 0;
auto b = 0;
{ auto const& cpp2_range = "abc"; for ( auto const& i : cpp2_range ) { do {
std::cout << i << a << b << '\n';
} while (false); (++a, ++b); }}
}
} |
Well I should have guessed. Even this works. |
See #449 (comment). It may work by accident. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for
loop (and other loops) don't accept several assignments insidenext
Reproduce Code
https://cpp2.godbolt.org/z/aqYqr63z5
Version
latest (38aec57)
Command lines
cppfront/cppfront $1.cpp2 -p
clang++-15 -Icppfront/include $1.cpp -std=c++20 -o $1
Expected result
Some block syntax for that assignment or diagnostic
Actual result
Compilation error
Additional notes
In grammar only single expr allowed
//G next-clause:
//G 'next' assignment-expression
Additionally, logical-or-expression could be logical.
Which can lead to compiled, but unused logical expression
for "abc' next a do (i) { //unused a
The text was updated successfully, but these errors were encountered: