]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/std/ranges/access/cdata.cc
1 // Copyright (C) 2019-2020 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
22 #include <testsuite_hooks.h>
31 int* data() { return &j
; }
32 const R
* data() const noexcept
{ return nullptr; }
36 VERIFY( std::ranges::cdata(r
) == (R
*)nullptr );
37 static_assert( noexcept(std::ranges::cdata(r
)) );
38 VERIFY( std::ranges::cdata(c
) == (R
*)nullptr );
39 static_assert( noexcept(std::ranges::cdata(c
)) );
46 VERIFY( std::ranges::cdata(a
) == a
+ 0 );
53 int* data() const { return nullptr; }
54 friend long* begin(R
&& r
); // this function is not defined
55 friend const long* begin(const R
& r
) { return &r
.l
; }
56 friend const short* begin(const R
&&); // not defined
59 // This is a lie, ranges::begin(R&&) returns a dangling iterator.
60 template<> constexpr bool std::ranges::enable_safe_range
<R
> = true;
67 VERIFY( std::ranges::cdata(r
) == std::ranges::data(c
) );
68 VERIFY( std::ranges::cdata(std::move(r
)) == std::ranges::begin(c
) );
69 VERIFY( std::ranges::cdata(std::move(c
)) == std::ranges::begin(c
) );