]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/variant/variant.variant/variant.status/valueless_by_exception.pass.cpp
Vendor import of libc++ trunk r300422:
[FreeBSD/FreeBSD.git] / test / std / utilities / variant / variant.variant / variant.status / valueless_by_exception.pass.cpp
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 // UNSUPPORTED: c++98, c++03, c++11, c++14
12
13 // The following compilers don't consider a type an aggregate type (and
14 // consequently not a literal type) if it has a base class at all.
15 // In C++17, an aggregate type is allowed to have a base class if it's not
16 // virtual, private, nor protected (e.g. ConstexprTestTypes:::NoCtors).
17 // XFAIL: gcc-5, gcc-6
18 // XFAIL: clang-3.5, clang-3.6, clang-3.7, clang-3.8
19 // XFAIL: apple-clang-6, apple-clang-7, apple-clang-8.0
20
21 // <variant>
22
23 // template <class ...Types> class variant;
24
25 // constexpr bool valueless_by_exception() const noexcept;
26
27 #include <cassert>
28 #include <string>
29 #include <type_traits>
30 #include <variant>
31
32 #include "archetypes.hpp"
33 #include "test_macros.h"
34 #include "variant_test_helpers.hpp"
35
36 int main() {
37   {
38     using V = std::variant<int, ConstexprTestTypes::NoCtors>;
39     constexpr V v;
40     static_assert(!v.valueless_by_exception(), "");
41   }
42   {
43     using V = std::variant<int, long, std::string>;
44     const V v("abc");
45     assert(!v.valueless_by_exception());
46   }
47 #ifndef TEST_HAS_NO_EXCEPTIONS
48   {
49     using V = std::variant<int, MakeEmptyT>;
50     V v;
51     assert(!v.valueless_by_exception());
52     makeEmpty(v);
53     assert(v.valueless_by_exception());
54   }
55 #endif
56 }