Created
September 28, 2013 21:40
-
-
Save quietfanatic/6746964 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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