Source of main.cpp:
typedef void (* fun_t)( void ); static const fun_t fun = [] { for (;;); }; int main( void ) { fun(); }
Listing:
... Region$$Table$$Base Region$$Table$$Limit main ** Section #2 '.debug_frame' (SHT_PROGBITS) Size : 68 bytes ...
Map file:
... Removing main.o(.text), (0 bytes). Removing main.o(.ARM.exidx.text.main), (8 bytes). Removing main.o(.ARM.use_no_argv), (4 bytes). ...
Why main function was removed?
Ok, so some more opportunities for dead code removal, definitely seems larger than necessary.
If foo uses a volatile loop variable it might distraction the compiler enough to keep it.
Code
is equivalent to the code below
int main( void ) { for (;;); }
So I think that main function has not dead code, it has infinite loop. The second version is compiled correctly.
main 0x08000230: e7fe .. B main ; 0x8000230 0x08000232: 0000 .. MOVS r0,r0
Is it bug of the compiler?
C++11, Lambda?
static const fun_t fun = [] { for (;;); };
Yes, but ARM Compiler 5 and GCC 6.3.1 do it properly.