Skip to content

Instantly share code, notes, and snippets.

@omochi
Created November 6, 2015 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omochi/3868fe6e88c504affee7 to your computer and use it in GitHub Desktop.
Save omochi/3868fe6e88c504affee7 to your computer and use it in GitHub Desktop.
// with gcc 4.8.2
#include <cstdio>
#include <functional>
int death = 1;
class Cat {
public:
std::function<void()> callback_;
void nya();
};
class App {
public:
Cat * cat_;
void main();
};
void Cat::nya() {
callback_();
}
void App::main() {
cat_ = new Cat();
cat_->callback_ = [this] {
auto this2 = this;
delete cat_;
if (death) {
cat_ = nullptr;
} else {
this2->cat_ = nullptr;
}
printf("ok\n");
};
cat_->nya();
}
int main(int argc, char * argv[]) {
App * app = new App();
app->main();
delete app;
return 0;
}
@omochi
Copy link
Author

omochi commented Nov 6, 2015

gcc5.2でもダメ。clang3.7はいけた。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment