brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 6c1bf8a Raw
69 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++1410// <optional>11 12// constexpr T& optional<T>::operator*() &;13 14#include <optional>15#include <type_traits>16#include <cassert>17 18#include "test_macros.h"19 20using std::optional;21 22struct X23{24    constexpr int test() const& {return 3;}25    int test() & {return 4;}26    constexpr int test() const&& {return 5;}27    int test() && {return 6;}28};29 30struct Y31{32    constexpr int test() {return 7;}33};34 35constexpr int36test()37{38    optional<Y> opt{Y{}};39    return (*opt).test();40}41 42int main(int, char**)43{44    {45        optional<X> opt; ((void)opt);46        ASSERT_SAME_TYPE(decltype(*opt), X&);47        ASSERT_NOEXCEPT(*opt);48    }49    {50        optional<X> opt(X{});51        assert((*opt).test() == 4);52    }53#if TEST_STD_VER >= 2654    {55      X x{};56      optional<X&> opt(x);57      ASSERT_SAME_TYPE(decltype(*opt), X&);58      ASSERT_NOEXCEPT(*opt);59    }60    {61      X x{};62      optional<X&> opt(x);63      assert((*opt).test() == 4);64    }65#endif66    static_assert(test() == 7, "");67    return 0;68}69