public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "shenrfen at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/40335] New: The implement of Switch statment is against with C++ standard Date: Thu, 04 Jun 2009 08:13:00 -0000 [thread overview] Message-ID: <bug-40335-17793@http.gcc.gnu.org/bugzilla/> (raw) Source code: 1.cpp #include <stdio.h> static int i; int main (void) { i = -1; switch ((signed char) i) { case 255: printf("255\n"); break; default: printf("default\n"); break; } } Compiling command : g++ 1.cpp && ./a.out result : 255 The expected result: default According to C++ standard, an integral promotion of expression "(signed char) i" should be performed firstly, the result of control expression should be 0xffff; then the label of case statment will be converted to int-type. So the expected result should be default in my opinion. Thanks very much. C++ standard: The condition shall be of integral type, enumeration type, or of a class type for which a single conversion function to integral or enumeration type exists (12.3). If the condition is of class type, the condition is converted by calling that conversion function, and the result of the conversion is used in place of the original condition for the remainder of this section. Integral promotions are performed. Any statement within the switch statement can be labeled with one or more case labels as follows: case constant-expression : where the constant-expression shall be an integral constant-expression. The integral constant-expression (5.19) is implicitly converted to the promoted type of the switch condition. -- Summary: The implement of Switch statment is against with C++ standard Product: gcc Version: unknown Status: UNCONFIRMED Severity: critical Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: shenrfen at gmail dot com GCC build triplet: x86 GCC host triplet: x86 GCC target triplet: x86 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40335
next reply other threads:[~2009-06-04 8:13 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2009-06-04 8:13 shenrfen at gmail dot com [this message] 2009-06-04 9:04 ` [Bug c++/40335] " rguenth at gcc dot gnu dot org 2009-06-04 9:09 ` shenrfen at gmail dot com 2009-06-04 9:47 ` shenrfen at gmail dot com 2009-06-04 10:05 ` rguenth at gcc dot gnu dot org 2009-06-04 10:24 ` shenrfen at gmail dot com 2009-06-04 10:46 ` paolo dot carlini at oracle dot com 2009-06-04 11:16 ` rguenth at gcc dot gnu dot org
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-40335-17793@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).