Fix PR31489 - std::function self-swap segfaults

llvm-svn: 290721
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: d566c345265421dedfb19d0c5a9a431d95b49b14
diff --git a/include/functional b/include/functional
index 0c450f1..eb8609f 100644
--- a/include/functional
+++ b/include/functional
@@ -1870,6 +1870,8 @@
 void
 function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
 {
+    if (_VSTD::addressof(__f) == this)
+      return;
     if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_)
     {
         typename aligned_storage<sizeof(__buf_)>::type __tempbuf;