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_03 b/include/__functional_03
index f8b5d95..a1cec8b 100644
--- a/include/__functional_03
+++ b/include/__functional_03
@@ -642,6 +642,8 @@
void
function<_Rp()>::swap(function& __f)
{
+ if (_VSTD::addressof(__f) == this)
+ return;
if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
{
typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
@@ -916,6 +918,8 @@
void
function<_Rp(_A0)>::swap(function& __f)
{
+ if (_VSTD::addressof(__f) == this)
+ return;
if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
{
typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
@@ -1190,6 +1194,8 @@
void
function<_Rp(_A0, _A1)>::swap(function& __f)
{
+ if (_VSTD::addressof(__f) == this)
+ return;
if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
{
typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
@@ -1464,6 +1470,8 @@
void
function<_Rp(_A0, _A1, _A2)>::swap(function& __f)
{
+ if (_VSTD::addressof(__f) == this)
+ return;
if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
{
typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
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;