Warn when unique objects might be duplicated in shared libraries (#117622)
[llvm-project.git] / libcxx / test / std / utilities / variant / variant.variant / variant.status / valueless_by_exception.pass.cpp
blob161c5fe0a0d8e7bca7bfe2b1ea08a21d6990bc9c
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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
11 // <variant>
13 // template <class ...Types> class variant;
15 // constexpr bool valueless_by_exception() const noexcept;
17 #include <cassert>
18 #include <string>
19 #include <type_traits>
20 #include <variant>
22 #include "archetypes.h"
23 #include "test_macros.h"
24 #include "variant_test_helpers.h"
27 int main(int, char**) {
29 using V = std::variant<int, long>;
30 constexpr V v;
31 static_assert(!v.valueless_by_exception(), "");
34 using V = std::variant<int, long>;
35 V v;
36 assert(!v.valueless_by_exception());
39 using V = std::variant<int, long, std::string>;
40 const V v("abc");
41 assert(!v.valueless_by_exception());
43 #ifndef TEST_HAS_NO_EXCEPTIONS
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());
51 #endif
53 return 0;