brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · c15d4e4 Raw
72 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 const T& optional<T>::operator*() const &;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    int test() const {return 2;}33};34 35int main(int, char**)36{37    {38        const optional<X> opt; ((void)opt);39        ASSERT_SAME_TYPE(decltype(*opt), X const&);40        ASSERT_NOEXCEPT(*opt);41    }42    {43        constexpr optional<X> opt(X{});44        static_assert((*opt).test() == 3, "");45    }46#if TEST_STD_VER >= 2647    {48      X x{};49      const optional<X&> opt{x};50      ASSERT_SAME_TYPE(decltype(*opt), X&);51      ASSERT_NOEXCEPT(*opt);52    }53    {54      X x{};55      const optional<const X&> opt{x};56      ASSERT_SAME_TYPE(decltype(*opt), const X&);57      ASSERT_NOEXCEPT(*opt);58    }59    {60      static constexpr X x{};61      constexpr optional<const X&> opt(x);62      static_assert((*opt).test() == 3);63    }64#endif65    {66        constexpr optional<Y> opt(Y{});67        assert((*opt).test() == 2);68    }69 70    return 0;71}72