Hello,
I have a question about converting non-capturing lambdas to function pointers at compile time.
Section 5.1.2.6 of the current working draft (N4431) describes the function pointer conversion for non-capturing lambdas as "...a public non-virtual non- explicit const conversion function to pointer to function...".
Is there a reason that this conversion could not be constexpr as well? This would allow for tables of non-capturing lambdas to be initialized at compile time and placed in read-only data sections.
Clang already optimizes the following definition into a read only section when compiling with -O2. ARM GCC 4.9 however, does not (it optimizes the conversion function to a constant address, but leaves the code to copy the addresses to the final array at a runtime). And neither compiler attempts to compute the table at compile time with default optimization levels.
extern int(* const functions[])() = {
[] { return 12;},
[] { return 31;},
[] { return 46;},
[] { return 79;},
[] { return 5;},
};
Any insight would be most welcome.
Thanks,
David