diff mbox series

[committed] libstdc++: Add default constructor to net::service_already_exists (PR 94199)

Message ID 20200316225435.GA3755249@redhat.com
State New
Headers show
Series [committed] libstdc++: Add default constructor to net::service_already_exists (PR 94199) | expand

Commit Message

Li, Pan2 via Gcc-patches March 16, 2020, 10:54 p.m. UTC
The service_already_exists exception type specified in the TS doesn't
have any constructors defined. Since its base class isn't default
constructible, that means has no usable constructors. This may be a
defect in the TS.

This patch fixes it by adding a default constructor, but making it
private. The make_service function is declared as a friend to be able to
call that private constructor.

	PR libstdc++/94199
	* include/experimental/executor (service_already_exists): Add default
	constructor. Declare make_service to be a friend.
	* testsuite/experimental/net/execution_context/make_service.cc: New
	test.

Tested powerpc64le-linux, committed to master.

I'll backport it to gcc-9 too.
commit c62f5e6e1f457462b1cea74792833821bbea64bb
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Mar 16 22:53:42 2020 +0000

    libstdc++: Add default constructor to net::service_already_exists (PR 94199)
    
    The service_already_exists exception type specified in the TS doesn't
    have any constructors defined. Since its base class isn't default
    constructible, that means has no usable constructors. This may be a
    defect in the TS.
    
    This patch fixes it by adding a default constructor, but making it
    private. The make_service function is declared as a friend to be able to
    call that private constructor.
    
            PR libstdc++/94199
            * include/experimental/executor (service_already_exists): Add default
            constructor. Declare make_service to be a friend.
            * testsuite/experimental/net/execution_context/make_service.cc: New
            test.

Comments

Li, Pan2 via Gcc-patches March 17, 2020, 11:01 a.m. UTC | #1
Hi,


On Mon, 16 Mar 2020 at 23:54, Jonathan Wakely via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> The service_already_exists exception type specified in the TS doesn't
> have any constructors defined. Since its base class isn't default
> constructible, that means has no usable constructors. This may be a
> defect in the TS.
>
> This patch fixes it by adding a default constructor, but making it
> private. The make_service function is declared as a friend to be able to
> call that private constructor.
>
>         PR libstdc++/94199
>         * include/experimental/executor (service_already_exists): Add default
>         constructor. Declare make_service to be a friend.
>         * testsuite/experimental/net/execution_context/make_service.cc: New
>         test.
>

The new test fails on arm-eabi / aarch64-elf (aka bare-metal / newlib
targets), because:
/arm-none-eabi/libstdc++-v3/include/experimental/executor:514: error:
'mutex' in namespace 'std' does not name a type
/arm-none-eabi/libstdc++-v3/include/experimental/executor:561: error:
'mutex' is not a member of 'std'
[...]

I don't remember what's the usual "fix" for this

Thanks,

Christophe



> Tested powerpc64le-linux, committed to master.
>
> I'll backport it to gcc-9 too.
>
Li, Pan2 via Gcc-patches March 17, 2020, 11:34 a.m. UTC | #2
On 17/03/20 12:01 +0100, Christophe Lyon wrote:
>Hi,
>
>
>On Mon, 16 Mar 2020 at 23:54, Jonathan Wakely via Gcc-patches
><gcc-patches@gcc.gnu.org> wrote:
>>
>> The service_already_exists exception type specified in the TS doesn't
>> have any constructors defined. Since its base class isn't default
>> constructible, that means has no usable constructors. This may be a
>> defect in the TS.
>>
>> This patch fixes it by adding a default constructor, but making it
>> private. The make_service function is declared as a friend to be able to
>> call that private constructor.
>>
>>         PR libstdc++/94199
>>         * include/experimental/executor (service_already_exists): Add default
>>         constructor. Declare make_service to be a friend.
>>         * testsuite/experimental/net/execution_context/make_service.cc: New
>>         test.
>>
>
>The new test fails on arm-eabi / aarch64-elf (aka bare-metal / newlib
>targets), because:
>/arm-none-eabi/libstdc++-v3/include/experimental/executor:514: error:
>'mutex' in namespace 'std' does not name a type
>/arm-none-eabi/libstdc++-v3/include/experimental/executor:561: error:
>'mutex' is not a member of 'std'
>[...]
>
>I don't remember what's the usual "fix" for this

I think they are just failing on some targets:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89760
Jonathan Wakely April 24, 2020, 1:19 p.m. UTC | #3
On 16/03/20 22:54 +0000, Jonathan Wakely wrote:
>The service_already_exists exception type specified in the TS doesn't
>have any constructors defined. Since its base class isn't default
>constructible, that means has no usable constructors. This may be a
>defect in the TS.
>
>This patch fixes it by adding a default constructor, but making it
>private. The make_service function is declared as a friend to be able to
>call that private constructor.
>
>	PR libstdc++/94199
>	* include/experimental/executor (service_already_exists): Add default
>	constructor. Declare make_service to be a friend.
>	* testsuite/experimental/net/execution_context/make_service.cc: New
>	test.

LWG preferred to make the constrcutor public, so this patch does that.

Tested x86_64-linux, committed to master.
diff mbox series

Patch

diff --git a/libstdc++-v3/include/experimental/executor b/libstdc++-v3/include/experimental/executor
index 5577623bb47..6955ead6bf5 100644
--- a/libstdc++-v3/include/experimental/executor
+++ b/libstdc++-v3/include/experimental/executor
@@ -127,7 +127,14 @@  inline namespace v1
   /// An extensible, type-safe, polymorphic set of services.
   class execution_context;
 
-  class service_already_exists : public logic_error { };
+  class service_already_exists : public logic_error
+  {
+    template<typename _Service, typename... _Args>
+      friend _Service&
+      make_service(execution_context&, _Args&&...);
+
+    service_already_exists() : logic_error("service already exists") { }
+  };
 
   template<typename _Tp> struct is_executor;
 
diff --git a/libstdc++-v3/testsuite/experimental/net/execution_context/make_service.cc b/libstdc++-v3/testsuite/experimental/net/execution_context/make_service.cc
new file mode 100644
index 00000000000..f134add48b5
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/net/execution_context/make_service.cc
@@ -0,0 +1,36 @@ 
+// Copyright (C) 2020 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-do compile { target c++14 } }
+
+#include <experimental/executor>
+
+namespace net = std::experimental::net;
+
+struct S : net::execution_context::service
+{
+  using key_type = S;
+
+  S(net::execution_context&);
+
+  void shutdown() noexcept override { }
+};
+
+void test01(net::execution_context& c)
+{
+  net::make_service<S>(c);
+}