mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-23 18:38:30 +08:00
[array.tuple]/1 says that instantiating tuple_element<N, array<T, M>> is ill-formed if N >= M. We didn't do that. Add a static_assert to cause a failure, and a test that checks that we failed
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@305191 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -296,6 +296,7 @@ class _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >
|
|||||||
template <size_t _Ip, class _Tp, size_t _Size>
|
template <size_t _Ip, class _Tp, size_t _Size>
|
||||||
class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
|
class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
|
||||||
{
|
{
|
||||||
|
static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
|
||||||
public:
|
public:
|
||||||
typedef _Tp type;
|
typedef _Tp type;
|
||||||
};
|
};
|
||||||
|
@@ -0,0 +1,35 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// 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>
|
||||||
|
|
||||||
|
// tuple_element<I, array<T, N> >::type
|
||||||
|
|
||||||
|
// Prevent -Warray-bounds from issuing a diagnostic when testing with clang verify.
|
||||||
|
#if defined(__clang__)
|
||||||
|
#pragma clang diagnostic ignored "-Warray-bounds"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
|
||||||
|
// std::array is explicitly allowed to be initialized with A a = { init-list };.
|
||||||
|
// Disable the missing braces warning for this reason.
|
||||||
|
#include "disable_missing_braces_warning.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
typedef double T;
|
||||||
|
typedef std::array<T, 3> C;
|
||||||
|
std::tuple_element<3, C> foo; // expected-note {{requested here}}
|
||||||
|
// expected-error@array:* {{static_assert failed "Index out of bounds in std::tuple_element<> (std::array)"}}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user