public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/36989] New: Wrong type for (... ? ... : ...)
@ 2008-07-31 15:26 terra at gnome dot org
2008-07-31 15:46 ` [Bug c/36989] " jsm28 at gcc dot gnu dot org
0 siblings, 1 reply; 2+ messages in thread
From: terra at gnome dot org @ 2008-07-31 15:26 UTC (permalink / raw)
To: gcc-bugs
With the code below, gcc complains over line 8, but not lines 14 and 17
because it deduces the wrong type for the ?: operator. The type of that
operator's result is dependent on whether something is a null pointer
constant and not. gcc fails to track that properly: it knows that
(const void *)0 is a null pointer constant, but it also thinks that
(void *)(void *)0 and (1 ? (void *)0 : (void *)0) are.
The chapter and verse is C99 6.15.15 #6: "if one operand is a null
pointer constant, the result has the type of the other operand;"
Null pointer constants are defined in C99 6.3.2.3 #3 to be an integer
constant expression with value zero or such an expression case to
type void *.
For the record, Sun's cc gets the invalid cases right, but also
rejects the valid case.
int
main (int argc, char **argv)
{
int *p;
int n;
/* Invalid: dereferences a void * */
*(n ? p : (const void *)0);
/* Valid since it dereferences an int* */
*(n ? p : (void *)0);
/* Invalid: dereferences a void * */
*(n ? p : (void *)(void *)0);
/* Invalid: dereferences a void * */
*(n ? p : (1 ? (void *)0 : (void *)0));
return 0;
}
--
Summary: Wrong type for (... ? ... : ...)
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: terra at gnome dot org
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=36989
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c/36989] Wrong type for (... ? ... : ...)
2008-07-31 15:26 [Bug c/36989] New: Wrong type for (... ? ... : ...) terra at gnome dot org
@ 2008-07-31 15:46 ` jsm28 at gcc dot gnu dot org
0 siblings, 0 replies; 2+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2008-07-31 15:46 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from jsm28 at gcc dot gnu dot org 2008-07-31 15:44 -------
Bug 456 covers c9[09]-const-expr-[12].c, bug 5675 covers
c9[0-9]-const-expr-3.c.
*** This bug has been marked as a duplicate of 456 ***
--
jsm28 at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36989
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-07-31 15:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-31 15:26 [Bug c/36989] New: Wrong type for (... ? ... : ...) terra at gnome dot org
2008-07-31 15:46 ` [Bug c/36989] " jsm28 at gcc dot gnu dot org
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).