libstdc++: Constrain net::executor constructors
authorJonathan Wakely <jwakely@redhat.com>
Fri, 24 Feb 2023 13:03:49 +0000 (13:03 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 24 Feb 2023 14:23:36 +0000 (14:23 +0000)
The TS says the arguments to these constructors shall meet the Executor
requirements, so it's undefined if they don't. Constraining on a subset
of those requirements won't affect valid cases, but prevents the
majority of invalid cases from trying to instantiate the constructor.

This prevents the non-explicit executor(Executor) constructor being a
candidate anywhere that a net::executor could be constructed e.g.
comparing ip::tcp::v4() == ip::udp::v4() would try to convert both
operands to executor using that constructor, then compare then using
operator==(const executor&, const executor&).

libstdc++-v3/ChangeLog:

* include/experimental/executor (executor): Constrain template
constructors.

libstdc++-v3/include/experimental/executor

index cd75d99..1dae892 100644 (file)
@@ -1012,6 +1012,9 @@ inline namespace v1
 
   class executor
   {
+    template<typename _Executor>
+      using _Context_t = decltype(std::declval<_Executor&>().context());
+
   public:
     // construct / copy / destroy:
 
@@ -1021,12 +1024,14 @@ inline namespace v1
     executor(const executor&) noexcept = default;
     executor(executor&&) noexcept = default;
 
-    template<typename _Executor>
+    template<typename _Executor,
+            typename = _Require<is_lvalue_reference<_Context_t<_Executor>>>>
       executor(_Executor __e)
       : _M_target(make_shared<_Tgt1<_Executor>>(std::move(__e)))
       { }
 
-    template<typename _Executor, typename _ProtoAlloc>
+    template<typename _Executor, typename _ProtoAlloc,
+            typename = _Require<is_lvalue_reference<_Context_t<_Executor>>>>
       executor(allocator_arg_t, const _ProtoAlloc& __a, _Executor __e)
       : _M_target(allocate_shared<_Tgt2<_Executor, _ProtoAlloc>>(__a,
            std::move(__e), __a))