1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // UNSUPPORTED: libcpp-no-concepts
11 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
12 
13 // constexpr R& base() & noexcept { return r_; }
14 // constexpr const R& base() const& noexcept { return r_; }
15 // constexpr R&& base() && noexcept { return std::move(r_); }
16 // constexpr const R&& base() const&& noexcept { return std::move(r_); }
17 
18 #include <ranges>
19 
20 #include <cassert>
21 #include <concepts>
22 
23 #include "test_macros.h"
24 
25 struct Base {
26   int *begin() const;
27   int *end() const;
28 };
29 
30 constexpr bool test()
31 {
32   using OwningView = std::ranges::owning_view<Base>;
33   OwningView ov;
34   decltype(auto) b1 = static_cast<OwningView&>(ov).base();
35   decltype(auto) b2 = static_cast<OwningView&&>(ov).base();
36   decltype(auto) b3 = static_cast<const OwningView&>(ov).base();
37   decltype(auto) b4 = static_cast<const OwningView&&>(ov).base();
38 
39   ASSERT_SAME_TYPE(decltype(b1), Base&);
40   ASSERT_SAME_TYPE(decltype(b2), Base&&);
41   ASSERT_SAME_TYPE(decltype(b3), const Base&);
42   ASSERT_SAME_TYPE(decltype(b4), const Base&&);
43 
44   assert(&b1 == &b2);
45   assert(&b1 == &b3);
46   assert(&b1 == &b4);
47 
48   ASSERT_NOEXCEPT(static_cast<OwningView&>(ov).base());
49   ASSERT_NOEXCEPT(static_cast<OwningView&&>(ov).base());
50   ASSERT_NOEXCEPT(static_cast<const OwningView&>(ov).base());
51   ASSERT_NOEXCEPT(static_cast<const OwningView&&>(ov).base());
52 
53   return true;
54 }
55 
56 int main(int, char**) {
57   test();
58   static_assert(test());
59 
60   return 0;
61 }
62