From 9c5ad80efd80e3962bb7e09bc3ab73545f56d549 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 18 Jan 2016 11:43:37 +0000 Subject: [PATCH] Fix construction of std::function from null pointer-to-member PR libstdc++/69293 * include/std/functional (_Function_base::_M_not_empty_function): Change overloads for pointers to take arguments by value. * testsuite/20_util/function/cons/57465.cc: Add tests for pointer-to-member cases. From-SVN: r232504 --- libstdc++-v3/ChangeLog | 6 ++++++ libstdc++-v3/include/std/functional | 8 ++++---- .../testsuite/20_util/function/cons/57465.cc | 24 ++++++++++++++++++---- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 74ef4f6..787bcd7 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,11 @@ 2016-01-18 Jonathan Wakely + PR libstdc++/69293 + * include/std/functional (_Function_base::_M_not_empty_function): + Change overloads for pointers to take arguments by value. + * testsuite/20_util/function/cons/57465.cc: Add tests for + pointer-to-member cases. + PR libstdc++/69340 * src/c++11/cow-stdexcept.cc (_txnal_cow_string_C1_for_exceptions): Use macros for exception handling and fix unused parameter warning. diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index 557156a..9799410 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -1633,13 +1633,13 @@ _GLIBCXX_MEM_FN_TRAITS(&&, false_type, true_type) template static bool - _M_not_empty_function(_Tp* const& __fp) - { return __fp; } + _M_not_empty_function(_Tp* __fp) + { return __fp != nullptr; } template static bool - _M_not_empty_function(_Tp _Class::* const& __mp) - { return __mp; } + _M_not_empty_function(_Tp _Class::* __mp) + { return __mp != nullptr; } template static bool diff --git a/libstdc++-v3/testsuite/20_util/function/cons/57465.cc b/libstdc++-v3/testsuite/20_util/function/cons/57465.cc index be2d132..7b13d4b 100644 --- a/libstdc++-v3/testsuite/20_util/function/cons/57465.cc +++ b/libstdc++-v3/testsuite/20_util/function/cons/57465.cc @@ -15,17 +15,33 @@ // with this library; see the file COPYING3. If not see // . -// libstdc++/57465 - // { dg-options "-std=gnu++11" } #include #include -int main() +void test01() { using F = void(); F* f = nullptr; std::function x(f); - VERIFY( !x ); + VERIFY( !x ); // libstdc++/57465 +} + +void test02() +{ + struct X { }; + int (X::*mf)() = nullptr; + std::function f = mf; + VERIFY( !f ); // libstdc++/69243 + + int X::*mp = nullptr; + f = mp; + VERIFY( !f ); +} + +int main() +{ + test01(); + test02(); } -- 2.7.4