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 // Clang 3.8 doesn't allow constexpr variables of non-literal type
14 // XFAIL: clang-3.8
15 
16 // <variant>
17 
18 // template <class ...Types> class variant;
19 
20 // constexpr bool valueless_by_exception() const noexcept;
21 
22 #include <cassert>
23 #include <string>
24 #include <type_traits>
25 #include <variant>
26 
27 #include "archetypes.hpp"
28 #include "test_macros.h"
29 #include "variant_test_helpers.hpp"
30 
31 int main() {
32   {
33     using V = std::variant<int, ConstexprTestTypes::NoCtors>;
34     constexpr V v;
35     static_assert(!v.valueless_by_exception(), "");
36   }
37   {
38     using V = std::variant<int, long, std::string>;
39     const V v("abc");
40     assert(!v.valueless_by_exception());
41   }
42 #ifndef TEST_HAS_NO_EXCEPTIONS
43   {
44     using V = std::variant<int, MakeEmptyT>;
45     V v;
46     assert(!v.valueless_by_exception());
47     makeEmpty(v);
48     assert(v.valueless_by_exception());
49   }
50 #endif
51 }
52