brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 161c5fe Raw
55 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 11// <variant>12 13// template <class ...Types> class variant;14 15// constexpr bool valueless_by_exception() const noexcept;16 17#include <cassert>18#include <string>19#include <type_traits>20#include <variant>21 22#include "archetypes.h"23#include "test_macros.h"24#include "variant_test_helpers.h"25 26 27int main(int, char**) {28  {29    using V = std::variant<int, long>;30    constexpr V v;31    static_assert(!v.valueless_by_exception(), "");32  }33  {34    using V = std::variant<int, long>;35    V v;36    assert(!v.valueless_by_exception());37  }38  {39    using V = std::variant<int, long, std::string>;40    const V v("abc");41    assert(!v.valueless_by_exception());42  }43#ifndef TEST_HAS_NO_EXCEPTIONS44  {45    using V = std::variant<int, MakeEmptyT>;46    V v;47    assert(!v.valueless_by_exception());48    makeEmpty(v);49    assert(v.valueless_by_exception());50  }51#endif52 53  return 0;54}55