here's something fun. say that x was declared in an outer scope as a typedef: typedef int x; now take the following code in a function body: auto x y = 67; this declares an automatic variable named y with type x. both gcc and clang parse this correctly. cherish this moment: it will be the last time in this blog post that gcc and clang agree on how to parse a declaration. let's change the declaration to look like this instead: auto x = 67; this should (presumably) declare a variable named x with an inferred type; the new binding should shadow the typedef. and this is exactly what clang does. gcc, on the other hand, <source>: In function 'main': <source>:4:12: error: expected identifier or '(' before '=' token 5 | auto x = 67; | ^ the problem is that auto can be either a storage-class specifier or a stand-in for a type specifier, depending on context. here, gcc parses x as a typedef, and so treats auto as a storage-class specifier, and therefore reports a syntax error. clang looks ahead before deciding how to treat x, so it's able to parse both declarations. so, what's the intended behavior? is this a bug in gcc? well... it's tough to say. as far as i can tell, the standard doesn't explicitly disambiguate here. funny enough, this same ambiguity arises in ansi c, since declarations which omit type specifiers are implicitly given type int, but ansi c explicitly disambiguates: If the [typedef] 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. so per ansi c rules, gcc is correct to error out here. but because i can't find any explicit disambiguation in the c23 standard, my interpretation is that clang's behavior is correct, since it fits in the grammar. and that's really funny, because it makes parsing really difficult. it might seem straightforward to just look ahead a token, but let's try throwing in some attributes: auto x [[asdf...
First seen: 2026-07-25 06:36
Last seen: 2026-07-26 17:01