brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 9873a76 Raw
46 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 bool optional<T>::has_value() const noexcept;13 14#include <optional>15#include <type_traits>16#include <cassert>17 18#include "test_macros.h"19 20int main(int, char**)21{22    using std::optional;23    {24        const optional<int> opt; ((void)opt);25        ASSERT_NOEXCEPT(opt.has_value());26        ASSERT_SAME_TYPE(decltype(opt.has_value()), bool);27    }28    {29        constexpr optional<int> opt;30        static_assert(!opt.has_value(), "");31    }32    {33        constexpr optional<int> opt(0);34        static_assert(opt.has_value(), "");35    }36#if TEST_STD_VER >= 2637    {38      static constexpr int i = 0;39      constexpr optional<const int&> opt{i};40      static_assert(opt.has_value());41    }42#endif43 44    return 0;45}46