re PR c/64423 (Incorrect column number of -Wchar-subscripts)
authorMarek Polacek <polacek@redhat.com>
Mon, 5 Jan 2015 12:03:57 +0000 (12:03 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Mon, 5 Jan 2015 12:03:57 +0000 (12:03 +0000)
PR c/64423
c-family/
* 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.
c/
* c-typeck.c (build_array_ref): Pass loc down to
warn_array_subscript_with_type_char.
cp/
* typeck.c (cp_build_array_ref): Pass loc down to
warn_array_subscript_with_type_char.
testsuite/
* gcc.dg/pr64423.c: New test.

From-SVN: r219186

gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/c-family/c-common.h
gcc/c/ChangeLog
gcc/c/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr64423.c [new file with mode: 0644]

index 47aa690dae7d94ca3b94044428508b5c6158cc76..960c7d1de2aaf7d0a042e1cc4d0db02f5a7eb3f7 100644 (file)
@@ -1,3 +1,11 @@
+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.
index 1066c6b96a799f152427f9f352a3709063683bca..af7a07e18b00df73ab3638f8ab76234467d28ba0 100644 (file)
@@ -11238,11 +11238,12 @@ check_missing_format_attribute (tree ltype, tree rtype)
    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
index c7eebcfc2ba9b328fcc3e655d0f9c3f652bcc06e..d1f09a63a8b410559f8d4eb72bfc01076e63bcae 100644 (file)
@@ -1014,7 +1014,7 @@ extern tree builtin_type_for_size (int, bool);
 
 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,
index 1661747d6046d5ef0e7debfbfd6096d99eeea240..7a0eda0dcefb936a8777e97e5c97932e6a779e6a 100644 (file)
@@ -1,3 +1,9 @@
+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
index abd452aed39cf05e262db2054811bf0338af7863..37beb6407acd80ecfcf4f1ff9c076bce51c04f3e 100644 (file)
@@ -2501,7 +2501,7 @@ build_array_ref (location_t loc, tree array, tree index)
   /* ??? 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);
index a6ce50bc6858983ffbeebe4be019a6da1128f8ef..de34ef92cf66ff6c83bce8289867156333c58929 100644 (file)
@@ -1,3 +1,9 @@
+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
index 9368b49b012c167f0effba5fa709a2d64cd8bf9d..fc85ec348211ccb684e20b20f767e6f612dca3b5 100644 (file)
@@ -3081,7 +3081,7 @@ cp_build_array_ref (location_t loc, tree array, tree idx,
     {
       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)))
        {
@@ -3191,7 +3191,7 @@ cp_build_array_ref (location_t loc, tree array, tree 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,
index 1690e7b02242dff8c9dd56b7a4649e0867fd6287..7293521c535b04510cfca2f78908d14c4be31d8c 100644 (file)
@@ -1,3 +1,8 @@
+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
diff --git a/gcc/testsuite/gcc.dg/pr64423.c b/gcc/testsuite/gcc.dg/pr64423.c
new file mode 100644 (file)
index 0000000..c228acb
--- /dev/null
@@ -0,0 +1,13 @@
+/* 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." } */
+}