From ab51d490d3f2899c0c8c55254031f81bcd5ebf0a Mon Sep 17 00:00:00 2001
From: mueller <mueller@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Sun, 29 Oct 2006 18:38:26 +0000
Subject: [PATCH] 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.



git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@118154 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/cp/ChangeLog                               |  6 ++++++
 gcc/cp/typeck.c                                |  2 ++
 gcc/testsuite/ChangeLog                        |  5 +++++
 gcc/testsuite/g++.dg/warn/Wchar-subscripts-2.C | 13 +++++++++++++
 4 files changed, 26 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/warn/Wchar-subscripts-2.C

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index a2f8b8aafcf8..1d46779ddfd2 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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.
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 0094323db753..46eee41b6dfc 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -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");
   }
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index de569bb604fd..f81e5837714b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 000000000000..5d19cd37ea43
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wchar-subscripts-2.C
@@ -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");
+}
-- 
GitLab