Specification: Specify that a function literal in an initializer list must be parenthesized #35674
Labels
area-specification (deprecated)
Deprecated: use area-language and a language- label.
closed-duplicate
Closed in favor of an existing report
type-bug
Incorrect behavior (everything from a crash to more subtle misbehavior)
Cf. #35673, it is currently not specified that the following is an error:
because the initializing expression in a
<fieldInitializer>
cannot be a function literal (the problem is that this in some cases introduces the need for an unlimited lookahead, and it's simply confusing for developers because of the syntactic ambiguity of a potentially large amount of code).We should specify this. It may be possible to relax these rules somewhat, e.g., by noting that
(int p)
cannot be an initializer, sox = (int p) { return 42; }
would not have the ambiguity: We definitely need to parse a function literal, and we can see, after a few tokens, that the{...}
is part of that function literal, and then it's required to have a constructor body or a semicolon afterwards. We might also insist that it is an error, because it's still a source of confusion for human readers that we have this big{...}
that might be a constructor body.The text was updated successfully, but these errors were encountered: