the perils of parsing type inference declarations in c

14 points by raymii


fanf

Oh how wonderfully cursed!

I think the ambiguity is resolved by a new sentence in C23 ยง 6.7.9 Type Definitions, which is very reminiscent of the C89 sentence that occurred in the same place (and which is quoted in the article). It suggests to me that a typedef name after auto should be parsed as a type specifier not a declarator. (Tho I agree the wording is obscure.)

C89:

A typedef name shares the same name space as other identifiers declared in ordinary declarators. If the identifier is redeclared in an inner scope or is declared as a member of a structure or union in the same or an inner scope, the type specifiers shall not be omitted in the inner declaration.

C23:

A typedef name shares the same name space as other identifiers declared in ordinary declarators. If the identifier is redeclared in an enclosed block, the type of the inner declaration shall not be inferred (6.7.10).