+2015-01-05 Marek Polacek <polacek@redhat.com>
+
+ PR c/64423
+ * c-common.c (warn_array_subscript_with_type_char): Add location_t
+ parameter. Use it.
+ * c-common.h (warn_array_subscript_with_type_char): Update
+ declaration.
+
2014-12-20 Edward Smith-Rowland <3dw4rd@verizon.net>
* c-cppbuiltin.c (__cpp_sized_deallocation): Uncomment and move macro.
warning only for non-constant value of type char. */
void
-warn_array_subscript_with_type_char (tree index)
+warn_array_subscript_with_type_char (location_t loc, tree index)
{
if (TYPE_MAIN_VARIANT (TREE_TYPE (index)) == char_type_node
&& TREE_CODE (index) != INTEGER_CST)
- warning (OPT_Wchar_subscripts, "array subscript has type %<char%>");
+ warning_at (loc, OPT_Wchar_subscripts,
+ "array subscript has type %<char%>");
}
/* Implement -Wparentheses for the unexpected C precedence rules, to
extern void c_common_mark_addressable_vec (tree);
-extern void warn_array_subscript_with_type_char (tree);
+extern void warn_array_subscript_with_type_char (location_t, tree);
extern void warn_about_parentheses (location_t,
enum tree_code,
enum tree_code, tree,
+2015-01-05 Marek Polacek <polacek@redhat.com>
+
+ PR c/64423
+ * c-typeck.c (build_array_ref): Pass loc down to
+ warn_array_subscript_with_type_char.
+
2014-12-20 Martin Uecker <uecker@eecs.berkeley.edu>
* c-typeck.c: New behavious for pointers to arrays with qualifiers
/* ??? Existing practice has been to warn only when the char
index is syntactically the index, not for char[array]. */
if (!swapped)
- warn_array_subscript_with_type_char (index);
+ warn_array_subscript_with_type_char (loc, index);
/* Apply default promotions *after* noticing character types. */
index = default_conversion (index);
+2015-01-05 Marek Polacek <polacek@redhat.com>
+
+ PR c/64423
+ * typeck.c (cp_build_array_ref): Pass loc down to
+ warn_array_subscript_with_type_char.
+
2014-12-31 Iain Sandoe <iain@codesourcery.com>
* parser.c (cp_parser_primary_expression): If parsing an
{
tree rval, type;
- warn_array_subscript_with_type_char (idx);
+ warn_array_subscript_with_type_char (loc, idx);
if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (idx)))
{
return error_mark_node;
}
- warn_array_subscript_with_type_char (idx);
+ warn_array_subscript_with_type_char (loc, idx);
ret = cp_build_indirect_ref (cp_build_binary_op (input_location,
PLUS_EXPR, ar, ind,
+2015-01-05 Marek Polacek <polacek@redhat.com>
+
+ PR c/64423
+ * gcc.dg/pr64423.c: New test.
+
2015-01-05 Hans-Peter Nilsson <hp@bitrange.com>
* gcc.dg/debug/debug-1.c: Pass -fno-if-conversion for
--- /dev/null
+/* PR c/64423 */
+/* { dg-do compile } */
+/* { dg-options "-Wchar-subscripts" } */
+
+int a[100];
+
+int
+f (char c)
+{
+ return a[c] /* { dg-warning "11:array subscript has type .char." } */
+ + a[c] /* { dg-warning "14:array subscript has type .char." } */
+ + a[c]; /* { dg-warning "16:array subscript has type .char." } */
+}