(build_array_ref): If -Wchar-subscripts, also warn in case when
authorRichard Kenner <kenner@gcc.gnu.org>
Mon, 21 Oct 1996 11:59:10 +0000 (07:59 -0400)
committerRichard Kenner <kenner@gcc.gnu.org>
Mon, 21 Oct 1996 11:59:10 +0000 (07:59 -0400)
pointer is being indexed.

From-SVN: r12983

gcc/c-typeck.c

index ec261853d0297d7ea57150bc5509c7518401be7b..9a0030d5a43ea48cc8f5ab607df6ce0d9118c151 100644 (file)
@@ -1451,6 +1451,14 @@ build_array_ref (array, index)
     tree ar = default_conversion (array);
     tree ind = default_conversion (index);
 
+    /* Do the same warning check as above, but only on the part that's
+       syntactically the index and only if it is also semantically
+       the index.  */
+    if (warn_char_subscripts
+       && TREE_CODE (TREE_TYPE (index)) == INTEGER_TYPE
+       && TYPE_MAIN_VARIANT (TREE_TYPE (index)) == char_type_node)
+      warning ("subscript has type `char'");
+
     /* Put the integer in IND to simplify error checking.  */
     if (TREE_CODE (TREE_TYPE (ar)) == INTEGER_TYPE)
       {