-
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
[BUG] Postfix operator to parenthesized expression isn't parsed in a statement #404
Comments
This doesn't work, either:
|
This also fails: https://cpp2.godbolt.org/z/qnfW3PPz7.
|
also fail. |
I think parameterized statement may be at fault. |
But this works: :() = 0; as int;
:() = 0; is int; |
@JohelEGP #441 fixes most of this issue. The only case that is not fixed by this PR is the following: main: (args) = { (args)&; } The parser is confused by main: (args) = { (args&); } We can solve that in two ways:
diff --git a/source/parse.h b/source/parse.h
index 8e6369d..a5cc1a8 100644
--- a/source/parse.h
+++ b/source/parse.h
@@ -5114,6 +5114,9 @@ private:
auto n = std::make_unique<statement_node>();
+ // Remember current position, in case this isn't a valid statement
+ auto start_pos = pos;
+
// If a parameter list is allowed here, try to parse one
if (parameters_allowed) {
n->parameters = parameter_declaration_list(false, true, false, true);
@@ -5193,6 +5196,10 @@ private:
}
else {
+ if (n->parameters) {
+ pos = start_pos; // backtrack
+ return statement(semicolon_required, equal_sign, false); // try parsing without parsing parameter list
+ }
return {};
}
} My gut feeling is that option 1 is the right one - the parsing should be context-free option 2 is a fix for case when it is not context-free. |
As I suspected, it was parameterized statements.
I do wonder if there's a third way.
Anything in-between would be a semantic violation, e.g.:
I think the third way I describe is context-free
The way I parse a statement that starts with parentheses |
Title: Postfix operator to parenthesized expression isn't parsed in a statement.
Minimal reproducer (https://cpp2.godbolt.org/z/eTGKsMdKn):
Commands:
Expected result:
Same as (https://cpp2.godbolt.org/z/x8qov5xvE):
Actual result and error:
The text was updated successfully, but these errors were encountered: