Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// When using first-class functions, c++11 will silently coerce a function returning a value
// into a std::function returning a reference, thus creating a ticking time bomb.
#include <stdio.h>
#include <functional>
const int& f1 (std::function<const int& ()> func) {
return func();
};
int f () { return 4; }
int main () {
const int& p = f1(f);
printf("%d\n", p); // Prints 32767 or somesuch.
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.