1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // UNSUPPORTED: c++03, c++11, c++14
11 
12 // <variant>
13 
14 // template <class ...Types> class variant;
15 
16 // constexpr bool valueless_by_exception() const noexcept;
17 
18 #include <cassert>
19 #include <string>
20 #include <type_traits>
21 #include <variant>
22 
23 #include "archetypes.h"
24 #include "test_macros.h"
25 #include "variant_test_helpers.h"
26 
27 
28 int main(int, char**) {
29   {
30     using V = std::variant<int, long>;
31     constexpr V v;
32     static_assert(!v.valueless_by_exception(), "");
33   }
34   {
35     using V = std::variant<int, long>;
36     V v;
37     assert(!v.valueless_by_exception());
38   }
39   {
40     using V = std::variant<int, long, std::string>;
41     const V v("abc");
42     assert(!v.valueless_by_exception());
43   }
44 #ifndef TEST_HAS_NO_EXCEPTIONS
45   {
46     using V = std::variant<int, MakeEmptyT>;
47     V v;
48     assert(!v.valueless_by_exception());
49     makeEmpty(v);
50     assert(v.valueless_by_exception());
51   }
52 #endif
53 
54   return 0;
55 }
56