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

llvm-svn: 305196
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 0c69d6e9bbb8f833daf75297a8b7fab724b33bc1
diff --git a/include/utility b/include/utility
index be73207..958378b 100644
--- a/include/utility
+++ b/include/utility
@@ -653,6 +653,12 @@
   class _LIBCPP_TEMPLATE_VIS tuple_size<pair<_T1, _T2> >
     : public integral_constant<size_t, 2> {};
 
+template <size_t _Ip, class _T1, class _T2>
+class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> >
+{
+    static_assert(_Ip < 2, "Index out of bounds in std::tuple_element<std::pair<T1, T2>>");
+};
+
 template <class _T1, class _T2>
 class _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> >
 {
diff --git a/include/variant b/include/variant
index 8505f32..8711ef6 100644
--- a/include/variant
+++ b/include/variant
@@ -278,7 +278,7 @@
 
 template <size_t _Ip, class... _Types>
 struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, variant<_Types...>> {
-  static_assert(_Ip < sizeof...(_Types));
+  static_assert(_Ip < sizeof...(_Types), "Index out of bounds in std::variant_alternative<>");
   using type = __type_pack_element<_Ip, _Types...>;
 };