]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/16307 (-Wchar-subscripts does not warn on pointers)
authorDirk Mueller <dmueller@suse.de>
Sun, 29 Oct 2006 18:38:26 +0000 (18:38 +0000)
committerDirk Mueller <mueller@gcc.gnu.org>
Sun, 29 Oct 2006 18:38:26 +0000 (18:38 +0000)
2006-10-29  Dirk Mueller  <dmueller@suse.de>

        PR c++/16307
        * typeck.c (build_array_ref): Warn for char subscriptions
        on pointers.

        * g++.dg/warn/Wchar-subscripts-2.C: New testcase.

From-SVN: r118154

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wchar-subscripts-2.C [new file with mode: 0644]

index a2f8b8aafcf87050aaf9de19b9d9d562600e3580..1d46779ddfd2bb55d5e53ae389ec1f16bf38686f 100644 (file)
@@ -1,3 +1,9 @@
+2006-10-29  Dirk Mueller  <dmueller@suse.de>
+
+       PR c++/16307
+       * typeck.c (build_array_ref): Warn for char subscriptions
+       on pointers.
+
 2006-10-29  Kazu Hirata  <kazu@codesourcery.com>
 
        * decl.c: Fix a comment typo.
index 0094323db753ce6a7eb98dd5c8e224a3a33ae101..46eee41b6dfc8495e467e720695f8c67682a946f 100644 (file)
@@ -2489,6 +2489,8 @@ build_array_ref (tree array, tree idx)
        return error_mark_node;
       }
 
+    warn_array_subscript_with_type_char (idx);
+
     return build_indirect_ref (cp_build_binary_op (PLUS_EXPR, ar, ind),
                               "array indexing");
   }
index de569bb604fd723fb1701f2bd3cc9fa7e5e806ea..f81e5837714b2a74c12c871c35124fb28c2b1224 100644 (file)
@@ -1,3 +1,8 @@
+2006-10-29  Dirk Mueller  <dmueller@suse.de>
+
+       PR c++/16307
+       * g++.dg/warn/Wchar-subscripts-2.C: New testcase.
+
 2006-10-29  Roger Sayle  <roger@eyesopen.com>
 
        PR tree-optimization/15458
diff --git a/gcc/testsuite/g++.dg/warn/Wchar-subscripts-2.C b/gcc/testsuite/g++.dg/warn/Wchar-subscripts-2.C
new file mode 100644 (file)
index 0000000..5d19cd3
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR c++/16307 */
+// { dg-do compile }
+// { dg-options "-Wchar-subscripts" }
+
+char foo (const char *s)
+{
+    return s [s ['\x80']];          // { dg-warning "array subscript" }
+}
+
+int main ()
+{
+    foo ("\x80");
+}