6.5.2.5p5 says
If a composite literal extends beyond the body of the function, the object has a static storage duration; otherwise, it automatically storage time associated with the closing unit.
Is it right to interpret the "enclosing block" here as the "innermost enclosing block"? (Because if it’s not the innermost, what is it?) Why do gcc and clang behave as if its lifespan was a closing function?
Example:
long foo(long*); void call_foo() { {foo(&(long){42});} {foo(&(long){42});} {foo(&(long){42});} {foo(&(long){42});} }
Code generated by gcc / clang with -O3:
call_foo: sub rsp, 40 mov rdi, rsp mov QWORD PTR [rsp], 42 call foo lea rdi, [rsp+8] mov QWORD PTR [rsp+8], 42 call foo lea rdi, [rsp+16] mov QWORD PTR [rsp+16], 42 call foo lea rdi, [rsp+24] mov QWORD PTR [rsp+24], 42 call foo add rsp, 40 ret call_foo2: sub rsp, 24 lea rdi, [rsp+8] mov QWORD PTR [rsp+8], 42 call foo lea rdi, [rsp+8] mov QWORD PTR [rsp+8], 42 call foo lea rdi, [rsp+8] mov QWORD PTR [rsp+8], 42 call foo lea rdi, [rsp+8] mov QWORD PTR [rsp+8], 42 call foo add rsp, 24 ret
source share