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.
This commit is contained in:
parent
5a26ba75de
commit
49adc06672
@ -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
|
||||
|
||||
/// @}
|
||||
|
||||
|
@ -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>(), "" );
|
||||
|
Loading…
Reference in New Issue
Block a user