This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] PR c++/16307


Hi, 

it seems the C++ frontend forgot to check for char subscriptions to pointers 
since apparently forever. bootstrapped, regtested on i686-suse-linux. Ok for 
mainline?

2006-10-29  Dirk Mueller  <dmueller@suse.de>

        * typeck.c (build_array_ref): Warn for char subscriptions
        on pointers.

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


--- cp/typeck.c
+++ 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");
   }
--- g++.dg/warn/Wchar-subscripts-2.C
+++ 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");
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]