https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77686
--- Comment #3 from ktkachov at gcc dot gnu.org --- A slightly adjusted testcase is: #include <functional> #include <iostream> struct C { void doCb () { size_t dummy_a = 1; std::cout << ""; auto tmp = this; std::function<void()> f; f = [this, &dummy_a]() {}; f = [this, tmp]() { if (this != tmp) __builtin_abort (); }; f (); } }; int main () { C c; c.doCb (); } This aborts on arm at -O2 but not at -O1