]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/span/layout_compat.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / span / layout_compat.cc
CommitLineData
a945c346 1// Copyright (C) 2020-2024 Free Software Foundation, Inc.
0f7cd5e5
JW
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
b9a2dce8 18// { dg-do compile { target c++20 } }
0f7cd5e5
JW
19
20#include <span>
21#include <cstddef>
22
23#if __has_include(<sys/uio.h>)
24#include <sys/uio.h>
25#else
26struct iovec { void* iov_base; std::size_t iov_len; };
27#endif
28
037ef219
JW
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.
0f7cd5e5 35template<typename T, typename U>
037ef219 36 constexpr bool same_size_and_alignment
0f7cd5e5
JW
37 = std::is_standard_layout_v<T> && std::is_standard_layout_v<U>
38 && sizeof(T) == sizeof(U) && alignof(T) == alignof(U);
0f7cd5e5
JW
39
40void
41test_pr95609()
42{
43 using rbuf = std::span<const std::byte>;
037ef219 44 static_assert(same_size_and_alignment<rbuf, struct iovec>);
0f7cd5e5 45
037ef219
JW
46 using wbuf = std::span<std::byte>;
47 static_assert(same_size_and_alignment<wbuf, struct iovec>);
0f7cd5e5 48}