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:
@@ -0,0 +1,25 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <utility>
|
||||
|
||||
// template <class T1, class T2> struct pair
|
||||
|
||||
// tuple_element<I, pair<T1, T2> >::type
|
||||
|
||||
#include <utility>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::pair<int, double> P;
|
||||
std::tuple_element<2, P>::type foo; // expected-note {{requested here}}
|
||||
// expected-error@utility:* {{static_assert failed "Index out of bounds in std::tuple_element<std::pair<T1, T2>>"}}
|
||||
}
|
||||
}
|
||||
@@ -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<>"}}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user