C++11 §5.1.2/6
The closure type for a lambda-expression with no lambda-capture has a [...] conversion function [...]. The value returned by this conversion function shall be the address of a function that, when invoked, has the same effect as invoking the closure type’s function call operator.
Note: this doesn't say that the conversion will always return the same value for the same type. So, does the following program run afoul of UB and all the meaning destruction that it implies?
int main() {
auto f = []{};
return ((+f) == (+f));
}
Note: I'd be thoroughly surprised if any real compiler were to give anything but true, but the question is about if a compiler could legally do anything else?
Edit:
C++11 §1.3.24
undefined behavior
behavior for which this International Standard imposes no requirements [ Note: Undefined behavior may be expected when this International Standard omits any explicit definition of behavior or when a program uses an erroneous construct or erroneous data
No, it's neither undefined nor unspecified. You don't know ahead of time whether it'll always be the same result (true or false), but there's nothing in that which means your program has undefined behaviour or that the result falls under the definition of an "unspecified value".
Simply put, this is about as UB as a call to rand(), or even to &someVariable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With