forked from OSchip/llvm-project
[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
llvm-svn: 305191
This commit is contained in:
parent
2e33bbaff0
commit
6db379a2c8
|
@ -296,6 +296,7 @@ class _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >
|
|||
template <size_t _Ip, class _Tp, size_t _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:
|
||||
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)"}}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue