libstdc++: Better preprocessor conditions in net::ip [PR 100286]
authorJonathan Wakely <jwakely@redhat.com>
Tue, 27 Apr 2021 12:06:43 +0000 (13:06 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 27 Apr 2021 13:04:36 +0000 (14:04 +0100)
commit9ee35a8685ee174c6914059143aceb7009d3e920
tree78d0c0a9f2212f3b9f17b8bf7d85514b7ecfd665
parent8aadb4fedb17e7a44583a7a5a4e96b1874e1ce98
libstdc++: Better preprocessor conditions in net::ip [PR 100286]

This improves the use of preprocessor conditionas to enable/disable
members of namespace net::ip according to what is supported by the
target. This fixes PR 100286 by ensuring that the to_string member
functions are always defined for the address_v4 and address_v6 classes.
On the other hand, the IP protocol classes and internet socket option
classes aren't useful at all if the corresponding constants (such as
IPPROTO_TCP or IPV6_MULTICAST_HOPS) aren't define. So those types are
not defined at all if they can't be used.

The net/internet/socket/opt.cc test uses __has_include to check whether
or not to expect the types to be available.

libstdc++-v3/ChangeLog:

PR libstdc++/100286
* include/experimental/internet (resolver_errc, resolver_category())
(make_error_code, make_error_condition): Define unconditionally,
only make enumerators and use of gai_strerror depend on the
availability of <netdb.h>.
(address_v4::to_string): Use correct constant for string length.
(address_v4::to_string, address_v6::to_string): Define
unconditionally, throw if unsupported.
(make_address_v4, make_address_v6): Define unconditionally.
Return an error if unsupported.
(tcp, udp, v6_only, unicast::hops, multicast::*): Define
conditionally,
* testsuite/experimental/net/internet/socket/opt.cc: Check for
<netinet/in.h> and <netinet/tcp.h> before using types from
namespace net::ip.
libstdc++-v3/include/experimental/internet
libstdc++-v3/testsuite/experimental/net/internet/socket/opt.cc