diff --git a/include/utility b/include/utility index be7320713..958378b8b 100644 --- a/include/utility +++ b/include/utility @@ -653,6 +653,12 @@ template class _LIBCPP_TEMPLATE_VIS tuple_size > : public integral_constant {}; +template +class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> > +{ + static_assert(_Ip < 2, "Index out of bounds in std::tuple_element>"); +}; + template class _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> > { diff --git a/include/variant b/include/variant index 8505f3262..8711ef6eb 100644 --- a/include/variant +++ b/include/variant @@ -278,7 +278,7 @@ struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, const volatile _Tp> template 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...>; }; diff --git a/test/libcxx/utilities/utility/pairs/pairs.pair/pair.tuple_element.fail.cpp b/test/libcxx/utilities/utility/pairs/pairs.pair/pair.tuple_element.fail.cpp new file mode 100644 index 000000000..2a92240a6 --- /dev/null +++ b/test/libcxx/utilities/utility/pairs/pairs.pair/pair.tuple_element.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// template struct pair + +// tuple_element >::type + +#include + +int main() +{ + { + typedef std::pair 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>"}} + } +} diff --git a/test/libcxx/utilities/variant/variant.variant/variant.helper/variant_alternative.fail.cpp b/test/libcxx/utilities/variant/variant.variant/variant.helper/variant_alternative.fail.cpp new file mode 100644 index 000000000..1c81b67e6 --- /dev/null +++ b/test/libcxx/utilities/variant/variant.variant/variant.helper/variant_alternative.fail.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// template struct variant_alternative; // undefined +// template struct variant_alternative; +// template struct variant_alternative; +// template struct variant_alternative; +// template +// using variant_alternative_t = typename variant_alternative::type; +// +// template +// struct variant_alternative>; + + +#include +#include + + +int main() +{ + { + typedef std::variant 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<>"}} + } +}