This is the mail archive of the gcc-bugs@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]

[Bug c++/29455] Issues with -Wchar-subscripts


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=29455

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2017-02-17
                 CC|                            |msebor at gcc dot gnu.org
     Ever confirmed|0                           |1
      Known to fail|                            |4.1.3, 4.2.2, 4.3.2, 4.6.0,
                   |                            |5.3.0, 6.3.0, 7.0

--- Comment #10 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed due to the missing warning on a['\300'] with today's top of trunk. 
The following test case shows that the C and C++ front ends behave nearly the
same (modulo the -Wmultichar warning), and that with optimization the
out-of-bounds constant character index is diagnosed by -Warray-bounds.

$ (cat t.c && set -x && for lang in c c++; do gcc -O2 -S -Wall -Wextra
-Wpedantic -fsigned-char -x$lang t.c; done)
int a[256];
int A(char c) { return a[c];      } // C and C++ warnings, OK.
int D(void)   { return a['%'];    } // Spurious C++ warning, no C warning
int B(void)   { return a['å'];    } // C++ warning, missing C warning
int C(void)   { return a['\300']; } // C++ warning, missing C warning
+ for lang in c c++
+ gcc -O2 -S -Wall -Wextra -Wpedantic -fsigned-char -xc t.c
t.c: In function ‘A’:
t.c:2:25: warning: array subscript has type ‘char’ [-Wchar-subscripts]
 int A(char c) { return a[c];      } // C and C++ warnings, OK.
                         ^
t.c: In function ‘B’:
t.c:4:26: warning: multi-character character constant [-Wmultichar]
 int B(void)   { return a['å'];    } // C++ warning, missing C warning
                          ^~~~
t.c:4:25: warning: array subscript is above array bounds [-Warray-bounds]
 int B(void)   { return a['å'];    } // C++ warning, missing C warning
                        ~^~~~~~
t.c: In function ‘C’:
t.c:5:25: warning: array subscript is below array bounds [-Warray-bounds]
 int C(void)   { return a['\300']; } // C++ warning, missing C warning
                        ~^~~~~~~~
+ for lang in c c++
+ gcc -O2 -S -Wall -Wextra -Wpedantic -fsigned-char -xc++ t.c
t.c:4:26: warning: multi-character character constant [-Wmultichar]
 int B(void)   { return a['å'];    } // C++ warning, missing C warning
                          ^~~~
t.c: In function ‘int A(char)’:
t.c:2:27: warning: array subscript has type ‘char’ [-Wchar-subscripts]
 int A(char c) { return a[c];      } // C and C++ warnings, OK.
                           ^
t.c: In function ‘int B()’:
t.c:4:30: warning: array subscript is above array bounds [-Warray-bounds]
 int B(void)   { return a['å'];    } // C++ warning, missing C warning
                        ~~~~~~^
t.c: In function ‘int C()’:
t.c:5:32: warning: array subscript is below array bounds [-Warray-bounds]
 int C(void)   { return a['\300']; } // C++ warning, missing C warning
                        ~~~~~~~~^

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