aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-common.c
diff options
context:
space:
mode:
authorGabriel Dos Reis <gdr@integrable-solutions.net>2005-11-24 02:02:26 +0000
committerGabriel Dos Reis <gdr@gcc.gnu.org>2005-11-24 02:02:26 +0000
commitff6b6641506a9aeab5dbb01a2ebd214ff3a942ba (patch)
treee7e85e47eb726ead6275d3e7b3b82823305a9fba /gcc/c-common.c
parent7fdc03073c4c0f664a6d5f1a5951b07c6e37fa44 (diff)
downloadgcc-ff6b6641506a9aeab5dbb01a2ebd214ff3a942ba.zip
gcc-ff6b6641506a9aeab5dbb01a2ebd214ff3a942ba.tar.gz
gcc-ff6b6641506a9aeab5dbb01a2ebd214ff3a942ba.tar.bz2
re PR c++/21667 (misleading warning about array subscription)
2005-11-23 Gabriel Dos Reis <gdr@integrable-solutions.net> PR c++/21667 * c-typeck.c (build_array_ref): Avoid code duplicate. Use common C/C++ diagnostic function warn_array_subscript_with_type_char. * c-common.h (warn_array_subscript_with_type_char): Declare. * c-common.c (warn_array_subscript_with_type_char): Define. cp/ 2005-11-23 Gabriel Dos Reis <gdr@integrable-solutions.net> PR c++/21667 * typeck.c (build_array_ref): Avoid code duplicate. Use common C/C++ diagnostic function warn_array_subscript_with_type_char. testsuite/ 2005-11-23 Gabriel Dos Reis <gdr@integrable-solutions.net> PR c++/21667 * gcc.dg/Wchar-subscripts.c: New. * g++.dg/warn/Wchar-subscripts.C: Likewise. From-SVN: r107448
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r--gcc/c-common.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 7b27ba0..b843df2 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -6284,4 +6284,20 @@ check_missing_format_attribute (tree ltype, tree rtype)
return false;
}
+/* Subscripting with type char is likely to lose on a machine where
+ chars are signed. So warn on any machine, but optionally. Don't
+ warn for unsigned char since that type is safe. Don't warn for
+ signed char because anyone who uses that must have done so
+ deliberately. Furthermore, we reduce the false positive load by
+ warning only for non-constant value of type char. */
+
+void
+warn_array_subscript_with_type_char (tree index)
+{
+ if (TYPE_MAIN_VARIANT (TREE_TYPE (index)) == char_type_node
+ && TREE_CODE (index) != INTEGER_CST)
+ warning (OPT_Wchar_subscripts, "array subscript has type %<char%>");
+}
+
+
#include "gt-c-common.h"