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 consider a type an aggregate type (and 14 // consequently not a literal type) if it has a base class at all. 15 // In C++17, an aggregate type is allowed to have a base class if it's not 16 // virtual, private, nor protected (e.g. ConstexprTestTypes:::NoCtors). 17 // XFAIL: gcc-5, gcc-6 18 // XFAIL: clang-3.5, clang-3.6, clang-3.7, clang-3.8 19 // XFAIL: apple-clang-6, apple-clang-7, apple-clang-8.0 20 21 // <variant> 22 23 // template <class ...Types> class variant; 24 25 // constexpr size_t index() const noexcept; 26 27 #include <cassert> 28 #include <string> 29 #include <type_traits> 30 #include <variant> 31 32 #include "archetypes.hpp" 33 #include "test_macros.h" 34 #include "variant_test_helpers.hpp" 35 36 int main() { 37 { 38 using V = std::variant<int, ConstexprTestTypes::NoCtors>; 39 constexpr V v; 40 static_assert(v.index() == 0, ""); 41 } 42 { 43 using V = std::variant<int, long>; 44 constexpr V v(std::in_place_index<1>); 45 static_assert(v.index() == 1, ""); 46 } 47 { 48 using V = std::variant<int, std::string>; 49 V v("abc"); 50 assert(v.index() == 1); 51 v = 42; 52 assert(v.index() == 0); 53 } 54 #ifndef TEST_HAS_NO_EXCEPTIONS 55 { 56 using V = std::variant<int, MakeEmptyT>; 57 V v; 58 assert(v.index() == 0); 59 makeEmpty(v); 60 assert(v.index() == std::variant_npos); 61 } 62 #endif 63 } 64