Make tuple_element static_assert in pair if the index is out of range. Also, add a message to variant_alternative<> in the similar case (it already asserted). Add tests for this

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@305196 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2017-06-12 16:13:17 +00:00
parent 568c481c7b
commit bc37f8d93d
4 changed files with 66 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <array>
// template <size_t I, class T> struct variant_alternative; // undefined
// template <size_t I, class T> struct variant_alternative<I, const T>;
// template <size_t I, class T> struct variant_alternative<I, volatile T>;
// template <size_t I, class T> struct variant_alternative<I, const volatile T>;
// template <size_t I, class T>
// using variant_alternative_t = typename variant_alternative<I, T>::type;
//
// template <size_t I, class... Types>
// struct variant_alternative<I, variant<Types...>>;
#include <variant>
#include <cassert>
int main()
{
{
typedef std::variant<int, double> T;
std::variant_alternative<2, T>::type foo; // expected-note {{requested here}}
// expected-error@variant:* {{static_assert failed "Index out of bounds in std::variant_alternative<>"}}
}
}