GCC (g++) emits a warning (-Wall) for the following code
% cat ary.C && g++ -Wall ary.C
int main()
{
int ary[256] = { 0 };
return ary['a'];
}
ary.C: In function 'int main()':
ary.C:4: warning: array subscript has type 'char'
The diagnostic is not helpful because the index is positive
(all character constants from the basic character set have
nonnegative values).
The warning should be emitted only if the index is unkonwn (at
compile time) and has type 'char'.
-- Gaby
--
Summary: misleading warning about array subscription
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gdr at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: plateform independent
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21667