From: Denis Zaitsev <zzz@anda.ru>
To: gcc@gcc.gnu.org, linux-gcc@vger.kernel.org
Subject: gcc-3.4.4-20050211: maybe a danger behaviour
Date: Sat, 26 Feb 2005 23:42:11 +0500 [thread overview]
Message-ID: <20050226234210.A2223@macacos.ward.six> (raw)
Consider the following example:
enum w {
// c=-1,
a,
b
};
whattodo (
char option
) {
static
struct todo {
enum w what;
char option;
} todos[]= {
{a,'a'},
{b,'b'},
{-1}
};
struct todo *p= todos;
do if (
(option && !option)
) break;
while ((++p)->what >= 0);
return p->what;
}
Compiling with -O[>0] and -Wall for x86 we have that code for
whattodo:
whattodo:
.L2:
jmp .L2
a) Formally, the code is correct. As p->what can never be < 0
according to its type.
b) GCC _silently_ allows the {-1} initialization for that type, even
with -Wall.
Uncommenting the c= -1 member of enum, or explicit casting p->what to
int solves the problem, of course. But maybe some warning would be
appropriate in such a situation? It takes some time for me to
recognize what leads me to that cool .L2: jmp .L2 from seemengly
harmless C code... Or maybe I don't know some healthy compiler
option?
reply other threads:[~2005-02-26 18:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20050226234210.A2223@macacos.ward.six \
--to=zzz@anda.ru \
--cc=gcc@gcc.gnu.org \
--cc=linux-gcc@vger.kernel.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: link
Be 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 NNTP newsgroup(s).