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-has-no-incomplete-ranges
11 
12 // constexpr R& base() & noexcept { return r_; }
13 // constexpr const R& base() const& noexcept { return r_; }
14 // constexpr R&& base() && noexcept { return std::move(r_); }
15 // constexpr const R&& base() const&& noexcept { return std::move(r_); }
16 
17 #include <ranges>
18 
19 #include <cassert>
20 #include <concepts>
21 
22 #include "test_macros.h"
23 
24 struct Base {
25   int *begin() const;
26   int *end() const;
27 };
28 
test()29 constexpr bool test()
30 {
31   using OwningView = std::ranges::owning_view<Base>;
32   OwningView ov;
33   decltype(auto) b1 = static_cast<OwningView&>(ov).base();
34   decltype(auto) b2 = static_cast<OwningView&&>(ov).base();
35   decltype(auto) b3 = static_cast<const OwningView&>(ov).base();
36   decltype(auto) b4 = static_cast<const OwningView&&>(ov).base();
37 
38   ASSERT_SAME_TYPE(decltype(b1), Base&);
39   ASSERT_SAME_TYPE(decltype(b2), Base&&);
40   ASSERT_SAME_TYPE(decltype(b3), const Base&);
41   ASSERT_SAME_TYPE(decltype(b4), const Base&&);
42 
43   assert(&b1 == &b2);
44   assert(&b1 == &b3);
45   assert(&b1 == &b4);
46 
47   ASSERT_NOEXCEPT(static_cast<OwningView&>(ov).base());
48   ASSERT_NOEXCEPT(static_cast<OwningView&&>(ov).base());
49   ASSERT_NOEXCEPT(static_cast<const OwningView&>(ov).base());
50   ASSERT_NOEXCEPT(static_cast<const OwningView&&>(ov).base());
51 
52   return true;
53 }
54 
main(int,char **)55 int main(int, char**) {
56   test();
57   static_assert(test());
58 
59   return 0;
60 }
61