[libcxx] r305191 - [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

Marshall Clow via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 12 07:41:37 PDT 2017


Author: marshall
Date: Mon Jun 12 09:41:37 2017
New Revision: 305191

URL: http://llvm.org/viewvc/llvm-project?rev=305191&view=rev
Log:
[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

Added:
    libcxx/trunk/test/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp
Modified:
    libcxx/trunk/include/array

Modified: libcxx/trunk/include/array
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/array?rev=305191&r1=305190&r2=305191&view=diff
==============================================================================
--- libcxx/trunk/include/array (original)
+++ libcxx/trunk/include/array Mon Jun 12 09:41:37 2017
@@ -296,6 +296,7 @@ class _LIBCPP_TEMPLATE_VIS tuple_size<ar
 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;
 };

Added: libcxx/trunk/test/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp?rev=305191&view=auto
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp (added)
+++ libcxx/trunk/test/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp Mon Jun 12 09:41:37 2017
@@ -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 at array:* {{static_assert failed "Index out of bounds in std::tuple_element<> (std::array)"}}
+    }
+}




More information about the cfe-commits mailing list