Browse Source
The json_array_foreach_ref macro declares an anonymous struct type
inside a for-loop initializer:
for (struct { size_t i; const struct json_array *a; } idx = ...
C11 6.8.5p3 constrains the for-loop initializer to only declare
objects with auto or register storage class — in other words, it is
only meant to create loop variables, not to define new types. However,
writing `struct { ... } x = ...;` does two things at once: it defines
a new type (the anonymous struct) and declares a variable.
In C11 standard 6.2.1, struct tags declared inside a for-loop
initializer get block scope of the enclosing block, so the type
definition escapes the for-loop, violating the "only objects"
constraint.
Extract the anonymous struct into a named struct json_array_iter
defined before the macro, so the for-loop initializer only declares a
plain object of an already-existing type.
Clang on armv7 iOS (via xcode-cross) enforces this constraint strictly
and rejects the original code with "declaration of non-local variable in
'for' loop".
pull/199/head
committed by
Jean-Baptiste Kempf
1 changed files with 6 additions and 1 deletions
Loading…
Reference in new issue