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