finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
{
idx = maybe_constant_value (idx, NULL_TREE, mce_true);
- if (TREE_CODE (idx) != INTEGER_CST || !INTEGRAL_TYPE_P (TREE_TYPE (idx)))
+ if (!INTEGRAL_TYPE_P (TREE_TYPE (idx)))
{
if (complain & tf_error)
- error ("pack index is not an integral constant");
+ error ("pack index has non-integral type %qT", TREE_TYPE (idx));
+ return error_mark_node;
+ }
+ if (TREE_CODE (idx) != INTEGER_CST)
+ {
+ if (complain & tf_error)
+ {
+ error ("pack index is not an integral constant");
+ cxx_constant_value (idx);
+ }
return error_mark_node;
}
if (tree_int_cst_sgn (idx) < 0)
{
if (complain & tf_error)
- error ("pack index is negative");
+ error ("pack index %qE is negative", idx);
return error_mark_node;
}
if (wi::to_widest (idx) >= TREE_VEC_LENGTH (types))
{
if (complain & tf_error)
- error ("pack index is out of range");
+ error ("pack index %qE is out of range for pack of length %qd",
+ idx, TREE_VEC_LENGTH (types));
return error_mark_node;
}
return TREE_VEC_ELT (types, tree_to_shwi (idx));
int
getT2 (auto... Ts)
{
- return Ts...[N]; // { dg-error "pack index is negative" }
+ return Ts...[N]; // { dg-error "pack index '-1' is negative" }
}
template<auto N, typename... Ts>
void
badtype2 ()
{
- Ts...[N] t; // { dg-error "pack index is out of range" }
+ Ts...[N] t; // { dg-error "pack index '1' is out of range for pack of length '1'" }
}
template<auto N, typename... Ts>
void
badtype4 ()
{
- Ts...[N] t; // { dg-error "pack index is negative" }
+ Ts...[N] t; // { dg-error "pack index '-1' is negative" }
}
int nonconst () { return 42; }
int p;
-using type = __type_pack_element<&p, int>; // { dg-error "not an integral constant" }
+using type = __type_pack_element<&p, int>; // { dg-error "non-integral type" }
using type = __type_pack_element<1, int>; // { dg-error "out of range" }
using type = __type_pack_element<2, int, char>; // { dg-error "out of range" }
using type = __type_pack_element<-1, int>; // { dg-error "negative" }
template <typename... _Elements> class tuple{};
template <unsigned long __i, typename... _Elements>
-__type_pack_element<__i, _Elements...> &get(tuple<_Elements...> &__t) noexcept; // { dg-error "index is out of range" }
+__type_pack_element<__i, _Elements...> &get(tuple<_Elements...> &__t) noexcept; // { dg-error "out of range" }
tuple<int,int> data;
template <unsigned long Level>
unsigned take_impl(unsigned idx) {
// { dg-error "tuple index must be in range" "" { target *-*-* } 0 }
// { dg-prune-output "no type named 'type' in .*_Nth_type" }
-// { dg-prune-output "pack index is out of range" }
+// { dg-prune-output "pack index '.' is out of range" }