The _Not_fn::_Not_fn<_Fn2>(_Fn2&&) ctor gets chosen by overload
resolution when trying to copy the call wrapper object (although only
for direct-initialization, because it's explicit). Rather than
constraining it using SFINAE I'm just adding a second parameter, so it
isn't viable for copying or moving the call wrapper.

I'm also reusing std::_Not_fn for std::experimental::not_fn, so we
don't need to fix bugs like this twice. _Not_fn uses std::invoke and
std::is_nothrow_callable, but we have __nonstandard versions of both
available in C++14.

        PR libstdc++/70564
        * include/experimental/functional (_Not_fn): Remove.
        (not_fn): Use std::_Not_fn.
        * include/std/functional (_Not_fn): Add second parameter to
        disambiguate copying from initialization by not_fn. Define for C++14.
        (not_fn): Add second argument to initialization.
        * testsuite/20_util/not_fn/1.cc: Copy call wrapper using
        direct-initialization.

Tested powerpc64le-linux, committing to trunk and gcc-6-branch.

commit a8f00b884083e0ffd9e9aaa919f6ea95adc57c2e
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Wed Oct 5 11:22:36 2016 +0100

    PR 70564 disambiguate constructors for not_fn call wrapper
    
        PR libstdc++/70564
        * include/experimental/functional (_Not_fn): Remove.
        (not_fn): Use std::_Not_fn.
        * include/std/functional (_Not_fn): Add second parameter to
        disambiguate copying from initialization by not_fn. Define for C++14.
        (not_fn): Add second argument to initialization.
        * testsuite/20_util/not_fn/1.cc: Copy call wrapper using
        direct-initialization.

diff --git a/libstdc++-v3/include/experimental/functional 
b/libstdc++-v3/include/experimental/functional
index 082e58c..db45665 100644
--- a/libstdc++-v3/include/experimental/functional
+++ b/libstdc++-v3/include/experimental/functional
@@ -378,64 +378,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #define __cpp_lib_experimental_not_fn 201406
 
-  /// Generalized negator.
-  template<typename _Fn>
-    class _Not_fn
-    {
-      _Fn _M_fn;
-
-    public:
-      template<typename _Fn2>
-       explicit
-       _Not_fn(_Fn2&& __fn)
-       : _M_fn(std::forward<_Fn2>(__fn)) { }
-
-      _Not_fn(const _Not_fn& __fn) = default;
-      _Not_fn(_Not_fn&& __fn) = default;
-      ~_Not_fn() = default;
-
-      template<typename... _Args>
-       auto
-       operator()(_Args&&... __args) &
-       noexcept(__is_nothrow_callable<_Fn&(_Args&&...)>::value)
-       -> decltype(!std::declval<result_of_t<_Fn&(_Args&&...)>>())
-       { return !std::__invoke(_M_fn, std::forward<_Args>(__args)...); }
-
-      template<typename... _Args>
-       auto
-       operator()(_Args&&... __args) const &
-       noexcept(__is_nothrow_callable<const _Fn&(_Args&&...)>::value)
-       -> decltype(!std::declval<result_of_t<const _Fn&(_Args&&...)>>())
-       { return !std::__invoke(_M_fn, std::forward<_Args>(__args)...); }
-
-      template<typename... _Args>
-       auto
-       operator()(_Args&&... __args) &&
-       noexcept(__is_nothrow_callable<_Fn&&(_Args&&...)>::value)
-       -> decltype(!std::declval<result_of_t<_Fn&&(_Args&&...)>>())
-       {
-         return !std::__invoke(std::move(_M_fn),
-                               std::forward<_Args>(__args)...);
-       }
-
-      template<typename... _Args>
-       auto
-       operator()(_Args&&... __args) const &&
-       noexcept(__is_nothrow_callable<const _Fn&&(_Args&&...)>::value)
-       -> decltype(!std::declval<result_of_t<const _Fn&&(_Args&&...)>>())
-       {
-         return !std::__invoke(std::move(_M_fn),
-                               std::forward<_Args>(__args)...);
-       }
-    };
-
   /// [func.not_fn] Function template not_fn
   template<typename _Fn>
     inline auto
     not_fn(_Fn&& __fn)
     noexcept(std::is_nothrow_constructible<std::decay_t<_Fn>, _Fn&&>::value)
     {
-      return _Not_fn<std::decay_t<_Fn>>{std::forward<_Fn>(__fn)};
+      return std::_Not_fn<std::decay_t<_Fn>>{std::forward<_Fn>(__fn), 0};
     }
 
 _GLIBCXX_END_NAMESPACE_VERSION
diff --git a/libstdc++-v3/include/std/functional 
b/libstdc++-v3/include/std/functional
index 74e65c7..1c7523e 100644
--- a/libstdc++-v3/include/std/functional
+++ b/libstdc++-v3/include/std/functional
@@ -2139,19 +2139,14 @@ _GLIBCXX_MEM_FN_TRAITS(&&, false_type, true_type)
     swap(function<_Res(_Args...)>& __x, function<_Res(_Args...)>& __y) noexcept
     { __x.swap(__y); }
 
-
-#if __cplusplus > 201402L
-
-#define __cpp_lib_not_fn 201603
-
-    /// Generalized negator.
+#if __cplusplus >= 201402L
+  /// Generalized negator.
   template<typename _Fn>
     class _Not_fn
     {
     public:
       template<typename _Fn2>
-       explicit
-       _Not_fn(_Fn2&& __fn)
+       _Not_fn(_Fn2&& __fn, int)
        : _M_fn(std::forward<_Fn2>(__fn)) { }
 
       _Not_fn(const _Not_fn& __fn) = default;
@@ -2161,21 +2156,21 @@ _GLIBCXX_MEM_FN_TRAITS(&&, false_type, true_type)
       template<typename... _Args>
        auto
        operator()(_Args&&... __args) &
-       noexcept(is_nothrow_callable_v<_Fn&(_Args&&...)>)
+       noexcept(__is_nothrow_callable<_Fn&(_Args&&...)>::value)
        -> decltype(!std::declval<result_of_t<_Fn&(_Args&&...)>>())
        { return !std::__invoke(_M_fn, std::forward<_Args>(__args)...); }
 
       template<typename... _Args>
        auto
        operator()(_Args&&... __args) const &
-       noexcept(is_nothrow_callable_v<const _Fn&(_Args&&...)>)
+       noexcept(__is_nothrow_callable<const _Fn&(_Args&&...)>::value)
        -> decltype(!std::declval<result_of_t<const _Fn&(_Args&&...)>>())
        { return !std::__invoke(_M_fn, std::forward<_Args>(__args)...); }
 
       template<typename... _Args>
        auto
        operator()(_Args&&... __args) &&
-       noexcept(is_nothrow_callable_v<_Fn&&(_Args&&...)>)
+       noexcept(__is_nothrow_callable<_Fn&&(_Args&&...)>::value)
        -> decltype(!std::declval<result_of_t<_Fn&&(_Args&&...)>>())
        {
          return !std::__invoke(std::move(_M_fn),
@@ -2185,7 +2180,7 @@ _GLIBCXX_MEM_FN_TRAITS(&&, false_type, true_type)
       template<typename... _Args>
        auto
        operator()(_Args&&... __args) const &&
-       noexcept(is_nothrow_callable_v<const _Fn&&(_Args&&...)>)
+       noexcept(__is_nothrow_callable<const _Fn&&(_Args&&...)>::value)
        -> decltype(!std::declval<result_of_t<const _Fn&&(_Args&&...)>>())
        {
          return !std::__invoke(std::move(_M_fn),
@@ -2195,6 +2190,11 @@ _GLIBCXX_MEM_FN_TRAITS(&&, false_type, true_type)
     private:
       _Fn _M_fn;
     };
+#endif // C++14
+
+#if __cplusplus > 201402L
+
+#define __cpp_lib_not_fn 201603
 
   /// [func.not_fn] Function template not_fn
   template<typename _Fn>
@@ -2202,7 +2202,7 @@ _GLIBCXX_MEM_FN_TRAITS(&&, false_type, true_type)
     not_fn(_Fn&& __fn)
     noexcept(std::is_nothrow_constructible<std::decay_t<_Fn>, _Fn&&>::value)
     {
-      return _Not_fn<std::decay_t<_Fn>>{std::forward<_Fn>(__fn)};
+      return _Not_fn<std::decay_t<_Fn>>{std::forward<_Fn>(__fn), 0};
     }
 
   // Searchers
@@ -2515,7 +2515,7 @@ _GLIBCXX_MEM_FN_TRAITS(&&, false_type, true_type)
       return std::make_pair(__last, __last);
     }
 
-#endif
+#endif // C++17
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
diff --git a/libstdc++-v3/testsuite/20_util/not_fn/1.cc 
b/libstdc++-v3/testsuite/20_util/not_fn/1.cc
index 375c7cc..8d6e9ec 100644
--- a/libstdc++-v3/testsuite/20_util/not_fn/1.cc
+++ b/libstdc++-v3/testsuite/20_util/not_fn/1.cc
@@ -84,6 +84,12 @@ test04()
   VERIFY( not_fn(f)(d) );
 }
 
+void
+test05()
+{
+  auto nf{ std::not_fn([] { return false; }) };
+}
+
 int
 main()
 {
@@ -91,4 +97,5 @@ main()
   test02();
   test03();
   test04();
+  test05();
 }
diff --git a/libstdc++-v3/testsuite/experimental/functional/not_fn.cc 
b/libstdc++-v3/testsuite/experimental/functional/not_fn.cc
index d508028..59d7621 100644
--- a/libstdc++-v3/testsuite/experimental/functional/not_fn.cc
+++ b/libstdc++-v3/testsuite/experimental/functional/not_fn.cc
@@ -84,6 +84,12 @@ test04()
   VERIFY( not_fn(f)(d) );
 }
 
+void
+test05()
+{
+  auto nf{ not_fn([] { return false; }) };
+}
+
 int
 main()
 {
@@ -91,4 +97,5 @@ main()
   test02();
   test03();
   test04();
+  test05();
 }

Reply via email to