This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/18411] Warning not legitimate
- From: "joseph at codesourcery dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 10 Nov 2004 01:15:42 -0000
- Subject: [Bug c/18411] Warning not legitimate
- References: <20041109232340.18411.manus@eiffel.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From joseph at codesourcery dot com 2004-11-10 01:15 -------
Subject: Re: Warning not legitimate
On Wed, 10 Nov 2004, manus at eiffel dot com wrote:
> Ok, so why don't you generate the warning only when it makes sense. In my
> original case, I was passing a char and tell the C compiler it was a function
> pointer expecting a char. In this scenario it should not produce any warning.
There is a limit to how much we care about code with undefined behavior on
execution. What type you pass in the source code is a red herring; if you
cast to a prototype type then the arguments will be getting converted to
that type, including if you'd passed a float argument. We aim for the
front end to pass down type-consistent code to the rest of the compiler
(which ideally would never need to call back into the earlier parts of the
compiler); where the standard requires type-inconsistent code to be
compiled but gives it execution-time undefined behavior, the only sensible
consistent structure for the rest of the compiler involves an abort in
place of the nonsensical code.
> If you have incompatible types (such as int where you expect a float/double)
> then I'm ok that you generate a warning (although I would prefer an error since
> the generated code is incorrect).
Remember DR#109:
A conforming implementation must not fail to translate a strictly
conforming program simply because *some* possible execution of that
program would result in undefined behavior.
The undefined behavior is only on execution, so the program must be
accepted. Because its execution is nonsensical - has no meaning whatever
- an abort is generated.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18411