On Thu, 8 Aug 2024, Jens Gustedt wrote: > No, the ambiguity is there because the first ( after the keyword could > start either a type in parenthesis or an expression, and among these a > compound literal. If that first parenthesis would be part of the > construct (as for the typeof or offsetof constructs) there would be no > ambiguity a the only look ahead would be balanced parenthesis parsing.
I don't consider this ambiguity / unbounded lookahead in any problematic sense. There are the following cases for sizeof: * Not followed by '(': sizeof unary-expression. * Followed by '(' then a token that does not start a type-name: sizeof unary-expression. * Followed by '(' then a token that does start a type-name: sizeof (type-name) later-tokens, where if later-tokens start with '{' then it's sizeof unary-expression and otherwise it's sizeof (type-name). The last case is not problematic because the parsing of the type-name doesn't depend at all on what comes after it; it's parsed exactly the same whether it's part of sizeof (type-name) or a compound literal. Fundamentally this is exactly the same as if a cast-expression starts with (type-name): until the end of the type name, you don't know whether it's a cast, or whether the cast-expression is actually a unary-expression which is a postfix-expression which is a compound-literal. In both cases, the parsing of a compound-literal is entered only after the initial (type-name) has been seen, because until after the (type-name) it's not known which construct is being parsed. -- Joseph S. Myers josmy...@redhat.com