]>
Commit | Line | Data |
---|---|---|
1 | // Copyright (C) 2020-2024 Free Software Foundation, Inc. | |
2 | // | |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
18 | // { dg-do compile { target c++20 } } | |
19 | ||
20 | #include <span> | |
21 | #include <cstddef> | |
22 | ||
23 | #if __has_include(<sys/uio.h>) | |
24 | #include <sys/uio.h> | |
25 | #else | |
26 | struct iovec { void* iov_base; std::size_t iov_len; }; | |
27 | #endif | |
28 | ||
29 | // std::span cannot possibly be layout-compatible with struct iovec because | |
30 | // iovec::iov_base is a void* and span<void> is ill-formed. Additionally, | |
31 | // the libstdc++ std::span uses [[no_unique_address]] on the second member, | |
32 | // so that it's not present for a span of static extent, and that affects | |
33 | // layout-compatibility too. | |
34 | // Use this to check the size and alignment are compatible. | |
35 | template<typename T, typename U> | |
36 | constexpr bool same_size_and_alignment | |
37 | = std::is_standard_layout_v<T> && std::is_standard_layout_v<U> | |
38 | && sizeof(T) == sizeof(U) && alignof(T) == alignof(U); | |
39 | ||
40 | void | |
41 | test_pr95609() | |
42 | { | |
43 | using rbuf = std::span<const std::byte>; | |
44 | static_assert(same_size_and_alignment<rbuf, struct iovec>); | |
45 | ||
46 | using wbuf = std::span<std::byte>; | |
47 | static_assert(same_size_and_alignment<wbuf, struct iovec>); | |
48 | } |