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 allow constexpr variables of non-literal type. 14 // XFAIL: gcc-5, gcc-6 15 // XFAIL: clang-3.5, clang-3.6, clang-3.7, clang-3.8 16 // XFAIL: apple-clang-6, apple-clang-7, apple-clang-8 17 18 // <variant> 19 20 // template <class ...Types> class variant; 21 22 // constexpr size_t index() const noexcept; 23 24 #include <cassert> 25 #include <string> 26 #include <type_traits> 27 #include <variant> 28 29 #include "archetypes.hpp" 30 #include "test_macros.h" 31 #include "variant_test_helpers.hpp" 32 33 int main() { 34 { 35 using V = std::variant<int, ConstexprTestTypes::NoCtors>; 36 constexpr V v; 37 static_assert(v.index() == 0, ""); 38 } 39 { 40 using V = std::variant<int, long>; 41 constexpr V v(std::in_place_index<1>); 42 static_assert(v.index() == 1, ""); 43 } 44 { 45 using V = std::variant<int, std::string>; 46 V v("abc"); 47 assert(v.index() == 1); 48 v = 42; 49 assert(v.index() == 0); 50 } 51 #ifndef TEST_HAS_NO_EXCEPTIONS 52 { 53 using V = std::variant<int, MakeEmptyT>; 54 V v; 55 assert(v.index() == 0); 56 makeEmpty(v); 57 assert(v.index() == std::variant_npos); 58 } 59 #endif 60 } 61