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 // Throwing bad_variant_access is supported starting in macosx10.13 13 // XFAIL: with_system_cxx_lib=macosx10.12 && !no-exceptions 14 // XFAIL: with_system_cxx_lib=macosx10.11 && !no-exceptions 15 // XFAIL: with_system_cxx_lib=macosx10.10 && !no-exceptions 16 // XFAIL: with_system_cxx_lib=macosx10.9 && !no-exceptions 17 18 // <variant> 19 20 // template <class ...Types> class variant; 21 22 // constexpr bool valueless_by_exception() const noexcept; 23 24 #include <cassert> 25 #include <string> 26 #include <type_traits> 27 #include <variant> 28 29 #include "archetypes.h" 30 #include "test_macros.h" 31 #include "variant_test_helpers.h" 32 33 34 int main(int, char**) { 35 { 36 using V = std::variant<int, long>; 37 constexpr V v; 38 static_assert(!v.valueless_by_exception(), ""); 39 } 40 { 41 using V = std::variant<int, long>; 42 V v; 43 assert(!v.valueless_by_exception()); 44 } 45 { 46 using V = std::variant<int, long, std::string>; 47 const V v("abc"); 48 assert(!v.valueless_by_exception()); 49 } 50 #ifndef TEST_HAS_NO_EXCEPTIONS 51 { 52 using V = std::variant<int, MakeEmptyT>; 53 V v; 54 assert(!v.valueless_by_exception()); 55 makeEmpty(v); 56 assert(v.valueless_by_exception()); 57 } 58 #endif 59 60 return 0; 61 } 62