public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "h dot b dot furuseth at usit dot uio dot no" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/29455] New: Issues with -Wchar-subscripts Date: Fri, 13 Oct 2006 12:51:00 -0000 [thread overview] Message-ID: <bug-29455-1038@http.gcc.gnu.org/bugzilla/> (raw) [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 1815 bytes --] [This is both a C and C++ bug report, not sure how to classify that.] 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 So, g++ -Wchar-subscripts warns "array subscript has type 'char'" about arr['%'] even though the index is guaranteed positive. gcc does not. OTOH, gcc does not warn about a['\300'] or a['å'] (8-bit a-ring), even with -fsigned-char which ensures that the subscript is negative. Note, arr['@'] COULD be a bug in the program with characters like @ which are not in the basic execution character set: C99 5.2.1p3; I haven't got the C++ standard. Only characters in that character set are guaranteed to be positive: C99 6.2.5p3. If the program is intended to be portable to other character sets, it is buggy. Even if gcc doesn't support a machine with that charset - if anyone does these days:-) So it might make sense to have a -Wchar-subscripts=2 warning which only assumes the basic execution character set, not the current character set. In preprocessor expressions I don't know if it should check the source or execution character set, or both... -- Summary: Issues with -Wchar-subscripts Product: gcc Version: 4.1.1 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: h dot b dot furuseth at usit dot uio dot no GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29455
next reply other threads:[~2006-10-13 12:51 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2006-10-13 12:51 h dot b dot furuseth at usit dot uio dot no [this message] 2006-10-13 16:54 ` [Bug c++/29455] " pinskia at gcc dot gnu dot org 2006-10-14 17:06 ` h dot b dot furuseth at usit dot uio dot no 2006-10-14 17:53 ` h dot b dot furuseth at usit dot uio dot no 2006-10-14 18:08 ` Andrew Pinski 2006-10-14 18:08 ` pinskia at gmail dot com 2006-10-17 12:49 ` h dot b dot furuseth at usit dot uio dot no 2006-10-24 6:32 ` gdr at integrable-solutions dot net 2006-10-24 8:20 ` h dot b dot furuseth at usit dot uio dot no
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-29455-1038@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).