+2012-11-14 Jonathan Wakely <jwakely.gcc@gmail.com>
+
+ PR libstdc++/55320
+ * include/std/functional (function::function(F)): Set _M_manager after
+ operations that could throw.
+ (_Function_base::_Ref_manager::_M_init_functor): Use addressof.
+ * include/tr1/functional
+ (_Function_base::_Ref_manager::_M_init_functor): Use addressof.
+ (_Function_base::_Base_manager::_M_get_pointer): Likewise.
+ * testsuite/20_util/function/cons/55320.cc: New.
+ * testsuite/20_util/function/cons/addressof.cc: New.
+ * testsuite/20_util/function/cons/callable.cc: Remove header.
+ * testsuite/20_util/bind/ref_neg.cc: Adjust dg-error line numbers.
+ * testsuite/tr1/3_function_objects/function/10.cc: New.
+
2012-11-14 Uros Bizjak <ubizjak@gmail.com>
* testsuite/26_numerics/complex/abi_tag.cc: Adjust expected
// <functional> -*- C++ -*-
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
-// 2011, 2012 Free Software Foundation, Inc.
+// Copyright (C) 2001-2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
static void
_M_init_functor(_Any_data& __functor, reference_wrapper<_Functor> __f)
{
- // TBD: Use address_of function instead.
- _Base::_M_init_functor(__functor, &__f.get());
+ _Base::_M_init_functor(__functor, std::__addressof(__f.get()));
}
};
if (_My_handler::_M_not_empty_function(__f))
{
+ _My_handler::_M_init_functor(_M_functor, std::move(__f));
_M_invoker = &_My_handler::_M_invoke;
_M_manager = &_My_handler::_M_manager;
- _My_handler::_M_init_functor(_M_functor, std::move(__f));
}
}
_M_get_pointer(const _Any_data& __source)
{
const _Functor* __ptr =
- __stored_locally? &__source._M_access<_Functor>()
+ __stored_locally? std::__addressof(__source._M_access<_Functor>())
/* have stored a pointer */ : __source._M_access<_Functor*>();
return const_cast<_Functor*>(__ptr);
}
static void
_M_init_functor(_Any_data& __functor, reference_wrapper<_Functor> __f)
{
- // TBD: Use address_of function instead.
- _Base::_M_init_functor(__functor, &__f.get());
+ _Base::_M_init_functor(__functor, std::__addressof(__f.get()));
}
};
-// Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+// Copyright (C) 2010-2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-// 20.7.11 Function template bind
+// 20.8.9 Function template bind
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
{
const int dummy = 0;
std::bind(&inc, _1)(0); // { dg-error "no match" }
- // { dg-error "rvalue|const" "" { target *-*-* } 1207 }
- // { dg-error "rvalue|const" "" { target *-*-* } 1221 }
- // { dg-error "rvalue|const" "" { target *-*-* } 1235 }
- // { dg-error "rvalue|const" "" { target *-*-* } 1249 }
+ // { dg-error "rvalue|const" "" { target *-*-* } 1206 }
+ // { dg-error "rvalue|const" "" { target *-*-* } 1220 }
+ // { dg-error "rvalue|const" "" { target *-*-* } 1234 }
+ // { dg-error "rvalue|const" "" { target *-*-* } 1248 }
std::bind(&inc, std::ref(dummy))(); // { dg-error "no match" }
}
--- /dev/null
+// Copyright (C) 2012 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// libstdc++/55320
+
+// { dg-options "-std=gnu++0x" }
+
+#include <functional>
+#include <testsuite_hooks.h>
+
+struct X
+{
+ X() { ++count; }
+ X(const X&) { throw 1; }
+ ~X() { --count; }
+ void operator()() { }
+ static int count;
+};
+
+int X::count = 0;
+
+int main()
+{
+ try
+ {
+ std::function<void()> f = X();
+ }
+ catch (int)
+ {
+ VERIFY( X::count == 0 );
+ }
+}
--- /dev/null
+// Copyright (C) 2012 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+
+#include <functional>
+
+struct F
+{
+ void operator()() { }
+ void operator&() const { }
+};
+
+void test01()
+{
+ F f;
+ std::function<void()> f1 = f;
+ std::function<void()> f2 = std::ref(f);
+}
+
+int main()
+{
+ test01();
+
+ return 0;
+}
// <http://www.gnu.org/licenses/>.
#include <functional>
-#include <testsuite_hooks.h>
void* f(std::function<void()>) { return nullptr; }
int f(std::function<void(int)>) { return 1; }
--- /dev/null
+// Copyright (C) 2012 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+
+#include <tr1/functional>
+
+struct F
+{
+ void operator()() { }
+ void operator&() const { }
+};
+
+void test01()
+{
+ F f;
+ std::tr1::function<void()> f1 = f;
+ std::tr1::function<void()> f2 = std::tr1::ref(f);
+}
+
+int main()
+{
+ test01();
+
+ return 0;
+}