an appropriate index type for the array. If non-NULL, NAME is
the name of the entity being declared. */
-tree
-compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
+static tree
+compute_array_index_type_loc (location_t name_loc, tree name, tree size,
+ tsubst_flags_t complain)
{
tree itype;
tree osize = size;
if (error_operand_p (size))
return error_mark_node;
+ location_t loc = cp_expr_loc_or_loc (size, name ? name_loc : input_location);
+
if (!type_dependent_expression_p (size))
{
osize = size = mark_rvalue_use (size);
if (!(complain & tf_error))
return error_mark_node;
if (name)
- error ("size of array %qD has non-integral type %qT", name, type);
+ error_at (loc, "size of array %qD has non-integral type %qT",
+ name, type);
else
- error ("size of array has non-integral type %qT", type);
+ error_at (loc, "size of array has non-integral type %qT", type);
size = integer_one_node;
}
}
{
tree folded = cp_fully_fold (size);
if (TREE_CODE (folded) == INTEGER_CST)
- pedwarn (input_location, OPT_Wpedantic,
- "size of array is not an integral constant-expression");
+ {
+ if (name)
+ pedwarn (loc, OPT_Wpedantic, "size of array %qD is not an "
+ "integral constant-expression", name);
+ else
+ pedwarn (loc, OPT_Wpedantic,
+ "size of array is not an integral constant-expression");
+ }
/* Use the folded result for VLAs, too; it will have resolved
SIZEOF_EXPR. */
size = folded;
return error_mark_node;
if (name)
- error ("size of array %qD is negative", name);
+ error_at (loc, "size of array %qD is negative", name);
else
- error ("size of array is negative");
+ error_at (loc, "size of array is negative");
size = integer_one_node;
}
/* As an extension we allow zero-sized arrays. */
else if (in_system_header_at (input_location))
/* Allow them in system headers because glibc uses them. */;
else if (name)
- pedwarn (input_location, OPT_Wpedantic, "ISO C++ forbids zero-size array %qD", name);
+ pedwarn (loc, OPT_Wpedantic,
+ "ISO C++ forbids zero-size array %qD", name);
else
- pedwarn (input_location, OPT_Wpedantic, "ISO C++ forbids zero-size array");
+ pedwarn (loc, OPT_Wpedantic,
+ "ISO C++ forbids zero-size array");
}
}
else if (TREE_CONSTANT (size)
return error_mark_node;
/* `(int) &fn' is not a valid array bound. */
if (name)
- error ("size of array %qD is not an integral constant-expression",
- name);
+ error_at (loc,
+ "size of array %qD is not an integral constant-expression",
+ name);
else
- error ("size of array is not an integral constant-expression");
+ error_at (loc, "size of array is not an integral constant-expression");
size = integer_one_node;
}
else if (pedantic && warn_vla != 0)
{
if (name)
- pedwarn (input_location, OPT_Wvla, "ISO C++ forbids variable length array %qD", name);
+ pedwarn (name_loc, OPT_Wvla,
+ "ISO C++ forbids variable length array %qD", name);
else
- pedwarn (input_location, OPT_Wvla, "ISO C++ forbids variable length array");
+ pedwarn (input_location, OPT_Wvla,
+ "ISO C++ forbids variable length array");
}
else if (warn_vla > 0)
{
if (name)
- warning (OPT_Wvla,
- "variable length array %qD is used", name);
+ warning_at (name_loc, OPT_Wvla,
+ "variable length array %qD is used", name);
else
warning (OPT_Wvla,
"variable length array is used");
return itype;
}
+tree
+compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
+{
+ return compute_array_index_type_loc (input_location, name, size, complain);
+}
+
/* Returns the scope (if any) in which the entity declared by
DECLARATOR will be located. If the entity was declared with an
unqualified name, NULL_TREE is returned. */
/* Figure out the index type for the array. */
if (size)
- itype = compute_array_index_type (name, size, tf_warning_or_error);
+ itype = compute_array_index_type_loc (loc, name, size,
+ tf_warning_or_error);
/* [dcl.array]
T is called the array element type; this type shall not be [...] an
+2018-11-29 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * g++.dg/cpp0x/constexpr-base6b.C: New.
+ * g++.dg/cpp0x/constexpr-47969.C: Test locations too.
+ * g++.dg/cpp0x/constexpr-48324.C: Likewise.
+ * g++.dg/cpp0x/constexpr-ex2.C: Likewise.
+ * g++.dg/cpp0x/scoped_enum2.C: Likewise.
+ * g++.dg/cpp1y/pr63996.C: Likewise.
+ * g++.dg/ext/constexpr-vla5.C: Likewise.
+ * g++.dg/ext/stmtexpr15.C: Likewise.
+ * g++.dg/ext/vla1.C: Likewise.
+ * g++.dg/other/fold1.C: Likewise.
+ * g++.dg/parse/array-size2.C: Likewise.
+ * g++.dg/parse/crash36.C: Likewise.
+ * g++.dg/ubsan/pr81530.C: Likewise.
+ * g++.dg/warn/Wvla-1.C: Likewise.
+ * g++.dg/warn/Wvla-2.C: Likewise.
+ * g++.old-deja/g++.brendan/array1.C: Likewise.
+ * g++.old-deja/g++.bugs/900402_02.C: Likewise.
+ * g++.old-deja/g++.law/init3.C: Likewise.
+ * g++.old-deja/g++.mike/p6149.C: Likewise.
+
2018-11-29 David Malcolm <dmalcolm@redhat.com>
PR c++/88121