Full code available here: https://godbolt.org/z/7sbxeM3WP
I was curious if it would be possible for a compiler to optimize
constexpr auto lambda = [](){return 5;};
constexpr auto lambda_same_definition = [](){return 5;};
such that there would only be one generated functor. I am aware of how lambda expressions work under the hood, creating anonymous functors for each expression. But at least here it looks pretty obvious since the expressions are literally the same, char for char, plus they're stored as constexpr
, that it doesn't seem out of the question that the compiler could fold the two functors into one. Of course I doubt this type of reasoning is doable in the general case, determining if two functions are the same sounds would probably be undecidable in the general case I'm guessing.
Unfortunately, it doesn't look like that's the case from my Godbolt snippet, it seems to have info for both under the type names*NL6lambdaMUlvE_E1
and NL22lambda_same_definitionMUlvE_E
.
So my question is, is this a quality of implementation issue? Or is there something in the Standard that forbids this optimization?