[cfe-dev] QOI issue for -Wchar-subscripts?
Marshall Clow
mclow.lists at gmail.com
Wed Feb 2 16:49:49 PST 2011
Given the following bit of code:
> #include <iostream>
>
> const char k12 = '\014';
>
> int main( int argc, char *argv [] )
> {
> char str[80];
> char c = 45;
>
> str [ '\n' ] = 'a';
> str [ 23 ] = 'b';
> str [ k12 ] = 'c';
> str [ c ] = 'd';
>
> return 0;
> }
>
and the following invocation:
> clang++ ~/junk.cpp -o ~/junk -Wchar-subscripts ; ~/junk
How many warnings should be emitted?
My answer:
Probably one. Maybe two, since 'k12' is also a char - but it's a constant.
What does clang do?
> /Users/marshall/junk.cpp:10:6: warning: array subscript is of type 'char' [-Wchar-subscripts]
> str [ '\n' ] = 'a';
> ^ ~~~~
> /Users/marshall/junk.cpp:12:6: warning: array subscript is of type 'char' [-Wchar-subscripts]
> str [ k12 ] = 'c';
> ^ ~~~
> /Users/marshall/junk.cpp:13:6: warning: array subscript is of type 'char' [-Wchar-subscripts]
> str [ c ] = 'd';
> ^ ~
> 3 warnings generated.
Warning on str [ '\n' ] just doesn't seem to be helpful to me.
[ Note: clang emits only two warnings when compiling this code as C ]
What do other people think?
-- Marshall
Marshall Clow Idio Software <mailto:mclow.lists at gmail.com>
A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
-- Yu Suzuki
More information about the cfe-dev
mailing list