re PR c++/16307 (-Wchar-subscripts does not warn on pointers)

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
This commit is contained in:
Dirk Mueller 2006-10-29 18:38:26 +00:00 committed by Dirk Mueller
parent 3f07249e98
commit 0958b0d31d
4 changed files with 26 additions and 0 deletions

View 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.

View 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");
}

View 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

View File

@ -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");
}