public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed 1/3] libstdc++ Simplify definition of net::socket_base constants
@ 2021-04-23 12:58 Jonathan Wakely
  2021-04-23 12:59 ` [committed 2/3] libstdc++ Clarify argument to net::io_context::async_wait Jonathan Wakely
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jonathan Wakely @ 2021-04-23 12:58 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 503 bytes --]

libstdc++-v3/ChangeLog:

	* include/experimental/socket (socket_base::shutdown_type):
	(socket_base::wait_type, socket_base::message_flags):
	Remove enumerators. Initialize constants directly with desired
	values.
	(socket_base::message_flags): Make all operators constexpr and
	noexcept.
	* testsuite/util/testsuite_common_types.h (test_bitmask_values):
	New test utility.
	* testsuite/experimental/net/socket/socket_base.cc: New test.

Tested powerpc64le-linux and sparc-solaris. Committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 9075 bytes --]

commit a752a43073dc49909c017fd52feacd7526ed31c0
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Apr 23 13:25:56 2021

    libstdc++ Simplify definition of net::socket_base constants
    
    libstdc++-v3/ChangeLog:
    
            * include/experimental/socket (socket_base::shutdown_type):
            (socket_base::wait_type, socket_base::message_flags):
            Remove enumerators. Initialize constants directly with desired
            values.
            (socket_base::message_flags): Make all operators constexpr and
            noexcept.
            * testsuite/util/testsuite_common_types.h (test_bitmask_values):
            New test utility.
            * testsuite/experimental/net/socket/socket_base.cc: New test.

diff --git a/libstdc++-v3/include/experimental/socket b/libstdc++-v3/include/experimental/socket
index a5a23ed3c06..ec4ed9d95e2 100644
--- a/libstdc++-v3/include/experimental/socket
+++ b/libstdc++-v3/include/experimental/socket
@@ -250,37 +250,29 @@ inline namespace v1
       static const int _S_name = SO_SNDLOWAT;
     };
 
-    enum shutdown_type : int
-    {
-      __shutdown_receive	= SHUT_RD,
-      __shutdown_send		= SHUT_WR,
-      __shutdown_both		= SHUT_RDWR
-    };
-    static constexpr shutdown_type shutdown_receive	= __shutdown_receive;
-    static constexpr shutdown_type shutdown_send	= __shutdown_send;
-    static constexpr shutdown_type shutdown_both	= __shutdown_both;
+    enum shutdown_type : int { };
+    static constexpr shutdown_type shutdown_receive = (shutdown_type)SHUT_RD;
+    static constexpr shutdown_type shutdown_send    = (shutdown_type)SHUT_WR;
+    static constexpr shutdown_type shutdown_both    = (shutdown_type)SHUT_RDWR;
 
+    enum wait_type : int { };
 #ifdef _GLIBCXX_HAVE_POLL_H
-    enum wait_type : int
-    {
-      __wait_read		= POLLIN,
-      __wait_write		= POLLOUT,
-      __wait_error		= POLLERR
-    };
-    static constexpr wait_type wait_read		= __wait_read;
-    static constexpr wait_type wait_write		= __wait_write;
-    static constexpr wait_type wait_error		= __wait_error;
+    static constexpr wait_type wait_read  = (wait_type)POLLIN;
+    static constexpr wait_type wait_write = (wait_type)POLLOUT;
+    static constexpr wait_type wait_error = (wait_type)POLLERR;
+#else
+    static constexpr wait_type wait_read  = (wait_type)1;
+    static constexpr wait_type wait_write = (wait_type)2;
+    static constexpr wait_type wait_error = (wait_type)4;
 #endif
 
-    enum message_flags : int
-    {
-      __message_peek		= MSG_PEEK,
-      __message_oob		= MSG_OOB,
-      __message_dontroute	= MSG_DONTROUTE
-    };
-    static constexpr message_flags message_peek		= __message_peek;
-    static constexpr message_flags message_out_of_band	= __message_oob;
-    static constexpr message_flags message_do_not_route	= __message_dontroute;
+    enum message_flags : int { };
+    static constexpr message_flags message_peek
+      = (message_flags)MSG_PEEK;
+    static constexpr message_flags message_out_of_band
+      = (message_flags)MSG_OOB;
+    static constexpr message_flags message_do_not_route
+      = (message_flags)MSG_DONTROUTE;
 
     static const int max_listen_connections = SOMAXCONN;
 #endif
@@ -350,30 +342,37 @@ inline namespace v1
 
   constexpr socket_base::message_flags
   operator&(socket_base::message_flags __f1, socket_base::message_flags __f2)
+    noexcept
   { return socket_base::message_flags( int(__f1) & int(__f2) ); }
 
   constexpr socket_base::message_flags
   operator|(socket_base::message_flags __f1, socket_base::message_flags __f2)
+    noexcept
   { return socket_base::message_flags( int(__f1) | int(__f2) ); }
 
   constexpr socket_base::message_flags
   operator^(socket_base::message_flags __f1, socket_base::message_flags __f2)
+    noexcept
   { return socket_base::message_flags( int(__f1) ^ int(__f2) ); }
 
   constexpr socket_base::message_flags
   operator~(socket_base::message_flags __f)
+    noexcept
   { return socket_base::message_flags( ~int(__f) ); }
 
-  inline socket_base::message_flags&
+  constexpr socket_base::message_flags&
   operator&=(socket_base::message_flags& __f1, socket_base::message_flags __f2)
+    noexcept
   { return __f1 = (__f1 & __f2); }
 
-  inline socket_base::message_flags&
+  constexpr socket_base::message_flags&
   operator|=(socket_base::message_flags& __f1, socket_base::message_flags __f2)
+    noexcept
   { return __f1 = (__f1 | __f2); }
 
-  inline socket_base::message_flags&
+  constexpr socket_base::message_flags&
   operator^=(socket_base::message_flags& __f1, socket_base::message_flags __f2)
+    noexcept
   { return __f1 = (__f1 ^ __f2); }
 
 #if _GLIBCXX_HAVE_UNISTD_H
diff --git a/libstdc++-v3/testsuite/experimental/net/socket/socket_base.cc b/libstdc++-v3/testsuite/experimental/net/socket/socket_base.cc
new file mode 100644
index 00000000000..b0b02b4e560
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/net/socket/socket_base.cc
@@ -0,0 +1,45 @@
+// Copyright (C) 2020-2021 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/socket>
+#include <testsuite_common_types.h>
+
+using S = std::experimental::net::socket_base;
+using namespace std;
+
+void test_constants()
+{
+  static_assert( is_enum<S::shutdown_type>::value, "" );
+  static_assert( S::shutdown_receive != S::shutdown_send, "" );
+  static_assert( S::shutdown_receive != S::shutdown_both, "" );
+  static_assert( S::shutdown_send != S::shutdown_both, "" );
+
+  static_assert( is_enum<S::wait_type>::value, "" );
+  static_assert( S::wait_read != S::wait_write, "");
+  static_assert( S::wait_read != S::wait_error, "");
+  static_assert( S::wait_write != S::wait_error, "");
+
+  static_assert( __gnu_test::test_bitmask_values(
+	{S::message_peek, S::message_out_of_band, S::message_do_not_route}
+	), "each bitmask element is distinct" );
+
+  auto m = &S::max_listen_connections;
+  static_assert( is_same<decltype(m), const int*>::value, "" );
+}
+
diff --git a/libstdc++-v3/testsuite/util/testsuite_common_types.h b/libstdc++-v3/testsuite/util/testsuite_common_types.h
index a87aa0f8f9a..a9a44df9664 100644
--- a/libstdc++-v3/testsuite/util/testsuite_common_types.h
+++ b/libstdc++-v3/testsuite/util/testsuite_common_types.h
@@ -952,5 +952,104 @@ namespace __gnu_test
       }
   };
 #endif
+
+#if __cplusplus >= 201402L
+  // Check that bitmask type T supports all the required operators,
+  // with the required semantics. Check that each bitmask element
+  // has a distinct, nonzero value, and that each bitmask constant
+  // has no bits set which do not correspond to a bitmask element.
+  template<typename T>
+    constexpr bool
+    test_bitmask_values(std::initializer_list<T> elements,
+			std::initializer_list<T> constants = {})
+    {
+      const T t0{};
+
+      if (!(t0 == t0))
+	return false;
+      if (t0 != t0)
+	return false;
+
+      if (t0 & t0)
+	return false;
+      if (t0 | t0)
+	return false;
+      if (t0 ^ t0)
+	return false;
+
+      T all = t0;
+
+      for (auto t : elements)
+	{
+	  // Each bitmask element has a distinct value.
+	  if (t & all)
+	    return false;
+
+	  // Each bitmask element has a nonzero value.
+	  if (!bool(t))
+	    return false;
+
+	  // Check operators
+
+	  if (!(t == t))
+	    return false;
+	  if (t != t)
+	    return false;
+	  if (t == t0)
+	    return false;
+	  if (t == all)
+	    return false;
+
+	  if (t & t0)
+	    return false;
+	  if ((t | t0) != t)
+	    return false;
+	  if ((t ^ t0) != t)
+	    return false;
+
+	  if ((t & t) != t)
+	    return false;
+	  if ((t | t) != t)
+	    return false;
+	  if (t ^ t)
+	    return false;
+
+	  T t1 = t;
+	  if ((t1 &= t) != t)
+	    return false;
+	  if ((t1 |= t) != t)
+	    return false;
+	  if (t1 ^= t)
+	    return false;
+
+	  t1 = all;
+	  if ((t1 &= t) != (all & t))
+	    return false;
+	  t1 = all;
+	  if ((t1 |= t) != (all | t))
+	    return false;
+	  t1 = all;
+	  if ((t1 ^= t) != (all ^ t))
+	    return false;
+
+	  all |= t;
+	  if (!(all & t))
+	    return false;
+	}
+
+      for (auto t : constants)
+	{
+	  // Check that bitmask constants are composed of the bitmask elements.
+	  if ((t & all) != t)
+	    return false;
+	  if ((t | all) != all)
+	    return false;
+	}
+
+      return true;
+    }
+#endif // C++14
+
+
 } // namespace __gnu_test
 #endif

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [committed 2/3] libstdc++ Clarify argument to net::io_context::async_wait
  2021-04-23 12:58 [committed 1/3] libstdc++ Simplify definition of net::socket_base constants Jonathan Wakely
@ 2021-04-23 12:59 ` Jonathan Wakely
  2021-04-23 13:01 ` [committed 3/3] libstdc++: Allow net::io_context to compile without <poll.h> [PR 100180] Jonathan Wakely
  2021-04-26 20:20 ` [committed 1/3] libstdc++ Simplify definition of net::socket_base constants Jonathan Wakely
  2 siblings, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2021-04-23 12:59 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 215 bytes --]

Add a comment documenting the __w parameter of the private
ios_context::async_wait function. Add casts to callers, making the
conversions explicit.

Tested powerpc64le-linux and sparc-solaris. Committed to trunk.



[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 5470 bytes --]

commit 3517dfe05c05a48885149334143230fcf0ebe6be
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Apr 23 13:31:33 2021

    libstdc++: Clarify argument to net::io_context::async_wait
    
    Add a comment documenting the __w parameter of the private
    ios_context::async_wait function. Add casts to callers, making the
    conversions explicit.
    
    libstdc++-v3/ChangeLog:
    
            * include/experimental/io_context (io_context::async_wait): Add
            comment.
            * include/experimental/socket (basic_socket::async_connect):
            Cast wait_type constant to int.
            (basic_datagram_socket::async_receive): Likewise.
            (basic_datagram_socket::async_receive_from): Likewise.
            (basic_datagram_socket::async_send): Likewise.
            (basic_datagram_socket::async_send_to): Likewise.
            (basic_stream_socket::async_receive): Likewise.
            (basic_stream_socket::async_send): Likewise. Use io_context
            parameter directly, instead of via an executor.
            (basic_socket_acceptor::async_accept): Likewise.

diff --git a/libstdc++-v3/include/experimental/io_context b/libstdc++-v3/include/experimental/io_context
index c82f30cd119..82d7b4f545e 100644
--- a/libstdc++-v3/include/experimental/io_context
+++ b/libstdc++-v3/include/experimental/io_context
@@ -475,6 +475,9 @@ inline namespace v1
 	return 0;
       }
 
+    // The caller must know what the wait-type __w will be interpreted.
+    // In the current implementation the reactor is based on <poll.h>
+    // so the parameter must be one of POLLIN, POLLOUT or POLLERR.
     template<typename _Op>
       void
       async_wait(int __fd, int __w, _Op&& __op)
diff --git a/libstdc++-v3/include/experimental/socket b/libstdc++-v3/include/experimental/socket
index ec4ed9d95e2..09c3b729607 100644
--- a/libstdc++-v3/include/experimental/socket
+++ b/libstdc++-v3/include/experimental/socket
@@ -954,7 +954,7 @@ inline namespace v1
 	    }
 
 	  get_executor().context().async_wait( native_handle(),
-	      socket_base::wait_read,
+	      (int) socket_base::wait_read,
 	      [__h = std::move(__init.completion_handler),
                __ep = std::move(__endpoint),
                __fd = native_handle()]
@@ -1165,7 +1165,7 @@ inline namespace v1
             __init{__token};
 
 	  this->get_executor().context().async_wait(this->native_handle(),
-	      socket_base::wait_read,
+	      (int) socket_base::wait_read,
 	      [__h = std::move(__init.completion_handler),
                &__buffers, __flags = static_cast<int>(__flags),
                __fd = this->native_handle()]
@@ -1271,7 +1271,7 @@ inline namespace v1
             __init{__token};
 
 	  this->get_executor().context().async_wait( this->native_handle(),
-	      socket_base::wait_read,
+	      (int) socket_base::wait_read,
 	      [__h = std::move(__init.completion_handler),
                &__buffers, __flags = static_cast<int>(__flags),
                __sender = std::move(__sender),
@@ -1366,7 +1366,7 @@ inline namespace v1
             __init{__token};
 
 	  this->get_executor().context().async_wait( this->native_handle(),
-	      socket_base::wait_write,
+	      (int) socket_base::wait_write,
 	      [__h = std::move(__init.completion_handler),
                &__buffers, __flags = static_cast<int>(__flags),
                __fd = this->native_handle()]
@@ -1469,7 +1469,7 @@ inline namespace v1
             __init{__token};
 
 	  this->get_executor().context().async_wait( this->native_handle(),
-	      socket_base::wait_write,
+	      (int) socket_base::wait_write,
 	      [__h = std::move(__init.completion_handler),
                &__buffers, __flags = static_cast<int>(__flags),
                __recipient = std::move(__recipient),
@@ -1634,7 +1634,7 @@ inline namespace v1
 	    }
 
           this->get_executor().context().async_wait(this->native_handle(),
-	      socket_base::wait_read,
+	      (int) socket_base::wait_read,
 	      [__h = std::move(__init.completion_handler),
                &__buffers, __flags = static_cast<int>(__flags),
                __fd = this->native_handle()]
@@ -1741,7 +1741,7 @@ inline namespace v1
 	    }
 
           this->get_executor().context().async_wait(this->native_handle(),
-	      socket_base::wait_write,
+	      (int) socket_base::wait_write,
 	      [__h = std::move(__init.completion_handler),
                &__buffers, __flags = static_cast<int>(__flags),
                __fd = this->native_handle()]
@@ -2098,8 +2098,8 @@ inline namespace v1
           async_completion<_CompletionToken, void(error_code, socket_type)>
             __init{__token};
 
-	  __ctx.get_executor().context().async_wait(native_handle(),
-	      socket_base::wait_read,
+	  __ctx.async_wait(native_handle(),
+	      (int) socket_base::wait_read,
 	      [__h = std::move(__init.completion_handler),
                __connabort = enable_connection_aborted(),
                __fd = native_handle(),
@@ -2189,8 +2189,8 @@ inline namespace v1
           async_completion<_CompletionToken, void(error_code, socket_type)>
             __init{__token};
 
-	  __ctx.get_executor().context().async_wait(native_handle(),
-	      socket_base::wait_read,
+	  __ctx.async_wait(native_handle(),
+	      (int) socket_base::wait_read,
 	      [__h = std::move(__init.completion_handler),
               __ep = std::move(__endpoint),
                __connabort = enable_connection_aborted(),

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [committed 3/3] libstdc++: Allow net::io_context to compile without <poll.h> [PR 100180]
  2021-04-23 12:58 [committed 1/3] libstdc++ Simplify definition of net::socket_base constants Jonathan Wakely
  2021-04-23 12:59 ` [committed 2/3] libstdc++ Clarify argument to net::io_context::async_wait Jonathan Wakely
@ 2021-04-23 13:01 ` Jonathan Wakely
  2021-04-26 20:20 ` [committed 1/3] libstdc++ Simplify definition of net::socket_base constants Jonathan Wakely
  2 siblings, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2021-04-23 13:01 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 272 bytes --]

This adds dummy placeholders to net::io_context so that it can still be
compiled on targets without <poll.h>.

Tested powerpc64le-linux and sparc-solaris. Committed to trunk.

This could be backported so that it fixes PR 100180 everywhere, but
after the gcc-11 release.



[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 2170 bytes --]

commit 0e1e7b77904f1fe2a6dbfe84bb4fc026584ba480
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Apr 23 13:38:05 2021

    libstdc++: Allow net::io_context to compile without <poll.h> [PR 100180]
    
    This adds dummy placeholders to net::io_context so that it can still be
    compiled on targets without <poll.h>.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/100180
            * include/experimental/io_context (io_context): Define
            dummy_pollfd type so that most member functions still compile
            without <poll.h> and struct pollfd.

diff --git a/libstdc++-v3/include/experimental/io_context b/libstdc++-v3/include/experimental/io_context
index 82d7b4f545e..63d7db5b2d0 100644
--- a/libstdc++-v3/include/experimental/io_context
+++ b/libstdc++-v3/include/experimental/io_context
@@ -716,6 +716,7 @@ inline namespace v1
 
     struct __reactor
     {
+#ifdef _GLIBCXX_HAVE_POLL_H
       __reactor() : _M_fds(1)
       {
 	int __pipe[2];
@@ -739,6 +740,7 @@ inline namespace v1
 	::close(_M_fds.back().fd);
 	::close(_M_notify_wr);
       }
+#endif
 
       // write a notification byte to the pipe (ignoring errors)
       void _M_notify()
@@ -799,8 +801,12 @@ inline namespace v1
 	_M_notify();
       }
 
-# ifdef _GLIBCXX_HAVE_POLL_H
+#ifdef _GLIBCXX_HAVE_POLL_H
       using __fdvec = vector<::pollfd>;
+#else
+      struct dummy_pollfd { int fd = -1; short events = 0, revents = 0; };
+      using __fdvec = vector<dummy_pollfd>;
+#endif
 
       // Find first element p such that !(p.fd < __fd)
       // N.B. always returns a dereferencable iterator.
@@ -816,6 +822,7 @@ inline namespace v1
       __status
       wait(__fdvec& __fds, chrono::milliseconds __timeout)
       {
+#ifdef _GLIBCXX_HAVE_POLL_H
 	// XXX not thread-safe!
 	__fds = _M_fds;  // take snapshot to pass to poll()
 
@@ -845,10 +852,14 @@ inline namespace v1
 	__fds.erase(__part, __fds.end());
 
 	return _S_ok;
+#else
+	(void) __timeout;
+	__fds.clear();
+	return _S_error;
+#endif
       }
 
       __fdvec _M_fds;	// _M_fds.back() is the read end of the self-pipe
-#endif
       int _M_notify_wr;	// write end of the self-pipe
     };
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [committed 1/3] libstdc++ Simplify definition of net::socket_base constants
  2021-04-23 12:58 [committed 1/3] libstdc++ Simplify definition of net::socket_base constants Jonathan Wakely
  2021-04-23 12:59 ` [committed 2/3] libstdc++ Clarify argument to net::io_context::async_wait Jonathan Wakely
  2021-04-23 13:01 ` [committed 3/3] libstdc++: Allow net::io_context to compile without <poll.h> [PR 100180] Jonathan Wakely
@ 2021-04-26 20:20 ` Jonathan Wakely
  2 siblings, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2021-04-26 20:20 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 619 bytes --]

On 23/04/21 13:58 +0100, Jonathan Wakely wrote:
>libstdc++-v3/ChangeLog:
>
>	* include/experimental/socket (socket_base::shutdown_type):
>	(socket_base::wait_type, socket_base::message_flags):
>	Remove enumerators. Initialize constants directly with desired
>	values.
>	(socket_base::message_flags): Make all operators constexpr and
>	noexcept.
>	* testsuite/util/testsuite_common_types.h (test_bitmask_values):
>	New test utility.
>	* testsuite/experimental/net/socket/socket_base.cc: New test.

And similarly for the constants in net::ip_resolver_base.

Tested powerpc64le-linux and powerpc-aix. Committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 6513 bytes --]

commit 49adc066729bda093b0658e3926bbf64cd4628b3
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Apr 26 21:16:20 2021

    libstdc++: Simplify definition of net::ip::resolver_base constants
    
    libstdc++-v3/ChangeLog:
    
            * include/experimental/internet (resolver_base::flags): Remove
            enumerators. Initialize constants directly with desired values.
            Make all operators constexpr and noexcept.
            * testsuite/experimental/net/internet/resolver/base.cc: Use
            __gnu_test::test_bitmask_values for bitmask type. Check
            construction and destruction is protected.

diff --git a/libstdc++-v3/include/experimental/internet b/libstdc++-v3/include/experimental/internet
index cd19de59e70..d3321afb9c6 100644
--- a/libstdc++-v3/include/experimental/internet
+++ b/libstdc++-v3/include/experimental/internet
@@ -1649,27 +1649,16 @@ namespace ip
   class resolver_base
   {
   public:
-    enum flags : int
-    {
-      __flags_passive			= AI_PASSIVE,
-      __flags_canonical_name		= AI_CANONNAME,
-      __flags_numeric_host		= AI_NUMERICHOST,
+    enum flags : int { };
+    static constexpr flags passive		= (flags)AI_PASSIVE;
+    static constexpr flags canonical_name	= (flags)AI_CANONNAME;
+    static constexpr flags numeric_host		= (flags)AI_NUMERICHOST;
 #ifdef AI_NUMERICSERV
-      __flags_numeric_service		= AI_NUMERICSERV,
+    static constexpr flags numeric_service	= (flags)AI_NUMERICSERV;
 #endif
-      __flags_v4_mapped			= AI_V4MAPPED,
-      __flags_all_matching		= AI_ALL,
-      __flags_address_configured	= AI_ADDRCONFIG
-    };
-    static constexpr flags passive		= __flags_passive;
-    static constexpr flags canonical_name	= __flags_canonical_name;
-    static constexpr flags numeric_host		= __flags_numeric_host;
-#ifdef AI_NUMERICSERV
-    static constexpr flags numeric_service	= __flags_numeric_service;
-#endif
-    static constexpr flags v4_mapped		= __flags_v4_mapped;
-    static constexpr flags all_matching		= __flags_all_matching;
-    static constexpr flags address_configured	= __flags_address_configured;
+    static constexpr flags v4_mapped		= (flags)AI_V4MAPPED;
+    static constexpr flags all_matching		= (flags)AI_ALL;
+    static constexpr flags address_configured	= (flags)AI_ADDRCONFIG;
 
   protected:
     resolver_base() = default;
@@ -1677,34 +1666,34 @@ namespace ip
   };
 
   constexpr resolver_base::flags
-  operator&(resolver_base::flags __f1, resolver_base::flags __f2)
+  operator&(resolver_base::flags __f1, resolver_base::flags __f2) noexcept
   { return resolver_base::flags( int(__f1) & int(__f2) ); }
 
   constexpr resolver_base::flags
-  operator|(resolver_base::flags __f1, resolver_base::flags __f2)
+  operator|(resolver_base::flags __f1, resolver_base::flags __f2) noexcept
   { return resolver_base::flags( int(__f1) | int(__f2) ); }
 
   constexpr resolver_base::flags
-  operator^(resolver_base::flags __f1, resolver_base::flags __f2)
+  operator^(resolver_base::flags __f1, resolver_base::flags __f2) noexcept
   { return resolver_base::flags( int(__f1) ^ int(__f2) ); }
 
   constexpr resolver_base::flags
-  operator~(resolver_base::flags __f)
+  operator~(resolver_base::flags __f) noexcept
   { return resolver_base::flags( ~int(__f) ); }
 
-  inline resolver_base::flags&
-  operator&=(resolver_base::flags& __f1, resolver_base::flags __f2)
+  constexpr resolver_base::flags&
+  operator&=(resolver_base::flags& __f1, resolver_base::flags __f2) noexcept
   { return __f1 = (__f1 & __f2); }
 
-  inline resolver_base::flags&
-  operator|=(resolver_base::flags& __f1, resolver_base::flags __f2)
+  constexpr resolver_base::flags&
+  operator|=(resolver_base::flags& __f1, resolver_base::flags __f2) noexcept
   { return __f1 = (__f1 | __f2); }
 
-  inline resolver_base::flags&
-  operator^=(resolver_base::flags& __f1, resolver_base::flags __f2)
+  constexpr resolver_base::flags&
+  operator^=(resolver_base::flags& __f1, resolver_base::flags __f2) noexcept
   { return __f1 = (__f1 ^ __f2); }
 
-  // TODO define resolver_base::flags static constants for C++14 mode
+  // TODO define resolver_base::flags static constants in .so for C++14 mode
 
   /// @}
 
diff --git a/libstdc++-v3/testsuite/experimental/net/internet/resolver/base.cc b/libstdc++-v3/testsuite/experimental/net/internet/resolver/base.cc
index c9efd642ca9..23af4464b72 100644
--- a/libstdc++-v3/testsuite/experimental/net/internet/resolver/base.cc
+++ b/libstdc++-v3/testsuite/experimental/net/internet/resolver/base.cc
@@ -15,50 +15,30 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// { dg-do run { target c++14 } }
+// { dg-do compile { target c++14 } }
 // { dg-add-options net_ts }
 
 #include <experimental/internet>
+#include <testsuite_common_types.h>
 #include <testsuite_hooks.h>
 
-void
-test01()
-{
-  bool test __attribute__((unused)) = false;
+using std::experimental::net::ip::resolver_base;
 
-  using resolver = std::experimental::net::ip::resolver_base;
-
-  resolver::flags f = resolver::passive;
-
-  VERIFY( (f & resolver::numeric_host) == 0);
-  f &= resolver::numeric_host;
-  VERIFY( f == 0 );
-
-  VERIFY( (f | resolver::numeric_host) == resolver::numeric_host);
-  f |= resolver::numeric_host;
-  VERIFY( f == resolver::numeric_host );
-
-  VERIFY( (f ^ resolver::numeric_host) == 0 );
-  f ^= resolver::numeric_host;
-  VERIFY( f == 0 );
-
-  f = ~resolver::numeric_host;
-  VERIFY( (f & resolver::numeric_host) == 0);
-  VERIFY( (f | resolver::numeric_host) == ~resolver::flags{} );
-
-  (void) resolver::passive;
-  (void) resolver::canonical_name;
-  (void) resolver::numeric_host;
+static_assert( __gnu_test::test_bitmask_values({
+  resolver_base::passive,
+  resolver_base::canonical_name,
+  resolver_base::numeric_host,
 #ifdef AI_NUMERICSERV
-  (void) resolver::numeric_service;
+  resolver_base::numeric_service,
 #endif
-  (void) resolver::v4_mapped;
-  (void) resolver::all_matching;
-  (void) resolver::address_configured;
-}
+  resolver_base::v4_mapped,
+  resolver_base::all_matching,
+  resolver_base::address_configured
+}), "each bitmask element is distinct" );
 
-int
-main()
-{
-  test01();
-}
+static_assert( ! std::is_default_constructible<resolver_base>(), "protected" );
+static_assert( ! std::is_destructible<resolver_base>(), "protected" );
+
+struct Res : resolver_base { };
+static_assert( std::is_default_constructible<Res>(), "" );
+static_assert( std::is_destructible<Res>(), "" );

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-26 20:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-23 12:58 [committed 1/3] libstdc++ Simplify definition of net::socket_base constants Jonathan Wakely
2021-04-23 12:59 ` [committed 2/3] libstdc++ Clarify argument to net::io_context::async_wait Jonathan Wakely
2021-04-23 13:01 ` [committed 3/3] libstdc++: Allow net::io_context to compile without <poll.h> [PR 100180] Jonathan Wakely
2021-04-26 20:20 ` [committed 1/3] libstdc++ Simplify definition of net::socket_base constants Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).