// Copyright (C) 2020-2023 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
// .
// { dg-do run { target c++14 } }
#include
#include
#include
using S = std::experimental::net::socket_base;
using namespace std;
static_assert( ! is_default_constructible(), "protected" );
static_assert( ! is_destructible(), "protected" );
struct Sock : S { };
static_assert( is_default_constructible(), "" );
static_assert( is_destructible(), "" );
// Dummy protocol
struct P
{
struct endpoint
{
using protocol_type = P;
P protocol() const;
};
};
template
void check_gettable_sockopt()
{
P p;
static_assert( is_same().level(p)), int>(), "" );
static_assert( noexcept(declval().level(p)), "" );
static_assert( is_same().name(p)), int>(), "" );
static_assert( noexcept(declval().name(p)), "" );
static_assert( is_same().data(p)), void*>(), "" );
static_assert( noexcept(declval().data(p)), "" );
static_assert( is_same().size(p)), size_t>(), "" );
static_assert( noexcept(declval().size(p)), "" );
static_assert( is_same().resize(p, 0)), void>(), "" );
static_assert( ! noexcept(declval().resize(p, 0)), "" );
C opt;
VERIFY(opt.size(p) == sizeof(T));
}
template
void check_settable_sockopt()
{
P p;
static_assert( is_same().level(p)), int>(), "" );
static_assert( noexcept(declval().level(p)), "" );
static_assert( is_same().name(p)), int>(), "" );
static_assert( noexcept(declval().name(p)), "" );
static_assert( is_same().data(p)), const void*>(), "" );
static_assert( noexcept(declval().data(p)), "" );
static_assert( is_same().size(p)), size_t>(), "" );
static_assert( noexcept(declval().size(p)), "" );
C opt;
VERIFY(opt.size(p) == sizeof(T));
}
template
void check_boolean_sockopt()
{
check_gettable_sockopt();
check_settable_sockopt();
static_assert( is_destructible(), "" );
static_assert( is_nothrow_default_constructible(), "" );
static_assert( is_nothrow_copy_constructible(), "" );
static_assert( is_nothrow_copy_assignable(), "" );
static_assert( is_nothrow_constructible(), "" );
static_assert( ! is_convertible(), "constructor is explicit" );
static_assert( is_nothrow_assignable(), "" );
static_assert( is_same().value()), bool>(), "" );
static_assert( noexcept(declval().value()), "" );
static_assert( is_same(declval())), bool>(), "" );
static_assert( noexcept(static_cast(declval())), "" );
static_assert( is_same()), bool>(), "" );
static_assert( noexcept(!declval()), "" );
}
template
void check_integer_sockopt()
{
check_gettable_sockopt();
check_settable_sockopt();
static_assert( is_destructible(), "" );
static_assert( is_nothrow_default_constructible(), "" );
static_assert( is_nothrow_copy_constructible(), "" );
static_assert( is_nothrow_copy_assignable(), "" );
static_assert( is_nothrow_constructible(), "" );
static_assert( ! is_convertible(), "constructor is explicit" );
static_assert( is_nothrow_assignable(), "" );
static_assert( is_same().value()), int>(), "" );
static_assert( noexcept(declval().value()), "" );
}
void test_option_types()
{
#if __has_include()
check_boolean_sockopt();
check_boolean_sockopt();
check_boolean_sockopt();
check_boolean_sockopt();
check_gettable_sockopt();
check_settable_sockopt();
static_assert( is_destructible(), "" );
static_assert( is_nothrow_default_constructible(), "" );
static_assert( is_nothrow_copy_constructible(), "" );
static_assert( is_nothrow_copy_assignable(), "" );
static_assert( is_nothrow_constructible(), "" );
static_assert( is_same().enabled()), bool>(), "" );
static_assert( noexcept(declval().enabled()), "" );
static_assert( is_void().enabled(true))>(), "" );
static_assert( noexcept(declval().enabled(true)), "" );
static_assert( is_same().timeout()), chrono::seconds>(), "" );
static_assert( noexcept(declval().timeout()), "" );
static_assert( is_void().timeout(chrono::seconds()))>(), "" );
static_assert( noexcept(declval().timeout(chrono::seconds())), "" );
check_boolean_sockopt();
check_integer_sockopt();
check_integer_sockopt();
check_boolean_sockopt();
check_integer_sockopt();
check_integer_sockopt();
#endif
}
void test_constants()
{
static_assert( is_enum::value, "" );
#if __has_include() && defined SHUT_RDWR
static_assert( S::shutdown_receive != S::shutdown_send, "" );
static_assert( S::shutdown_receive != S::shutdown_both, "" );
static_assert( S::shutdown_send != S::shutdown_both, "" );
#endif
static_assert( is_enum::value, "" );
#if __has_include() && defined POLLIN
static_assert( S::wait_read != S::wait_write, "");
static_assert( S::wait_read != S::wait_error, "");
static_assert( S::wait_write != S::wait_error, "");
#endif
static_assert( is_enum::value, "" );
#if __has_include() && defined MSG_OOB
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" );
#endif
static_assert( is_same::value, "" );
}
int main()
{
test_option_types();
}