2 //===----------------------------------------------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 // UNSUPPORTED: c++98, c++03, c++11, c++14
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
23 // template <class ...Types> class variant;
25 // constexpr size_t index() const noexcept;
29 #include <type_traits>
32 #include "archetypes.hpp"
33 #include "test_macros.h"
34 #include "variant_test_helpers.hpp"
38 using V = std::variant<int, ConstexprTestTypes::NoCtors>;
40 static_assert(v.index() == 0, "");
43 using V = std::variant<int, long>;
44 constexpr V v(std::in_place_index<1>);
45 static_assert(v.index() == 1, "");
48 using V = std::variant<int, std::string>;
50 assert(v.index() == 1);
52 assert(v.index() == 0);
54 #ifndef TEST_HAS_NO_EXCEPTIONS
56 using V = std::variant<int, MakeEmptyT>;
58 assert(v.index() == 0);
60 assert(v.index() == std::variant_npos);