public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/13519] New: typeof(nonconst+const) is const
@ 2003-12-30 13:18 debian-gcc at lists dot debian dot org
2003-12-30 18:02 ` [Bug c/13519] " pinskia at gcc dot gnu dot org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: debian-gcc at lists dot debian dot org @ 2003-12-30 13:18 UTC (permalink / raw)
To: gcc-bugs
[forwarded from http://bugs.debian.org/208981]
Bug submitter writes:
Try compiling the following function with "gcc-3.3 -c const.c".
GCC gives "assignment of read-only variable" warnings on the
indicated lines. This shows that __typeof__ treats the
corresponding arguments as const.
void fn(void)
{
int n;
const int c;
{ __typeof__(n) a1; a1=0; }
{ __typeof__(c) a2; a2=0; } /* warning */
{ __typeof__(n+n) b0; b0=0; }
{ __typeof__(n+c) b1; b1=0; } /* warning */
{ __typeof__(c+n) b2; b2=0; }
{ __typeof__(c+c) b3; b3=0; } /* warning */
{ __typeof__(1+n) c0; c0=0; }
{ __typeof__(1+c) c1; c1=0; } /* warning */
{ __typeof__(n+1) c2; c2=0; }
{ __typeof__(c+1) c3; c3=0; }
{ __typeof__(((int)n)+((int)n)) d0; d0=0; }
{ __typeof__(((int)n)+((int)c)) d1; d1=0; } /* warning */
{ __typeof__(((int)c)+((int)n)) d2; d2=0; }
{ __typeof__(((int)c)+((int)c)) d3; d3=0; } /* warning */
{ __typeof__(((const int)n)+((const int)n)) e0; e0=0; }
{ __typeof__(((const int)n)+((const int)c)) e1; e1=0; } /* warning */
{ __typeof__(((const int)c)+((const int)n)) e2; e2=0; }
{ __typeof__(((const int)c)+((const int)c)) e3; e3=0; } /* warning */
}
The behavior at b1 and b2 seems inconsistent. If n+c is const,
then surely c+n should be as well, given that the addition
operator is commutative in all other respects.
Cases c0 to c3 show that GCC treats an integer constant as a
non-const rvalue. Cases d0 to d3 and e0 to e3 show that casts
have no effect on the constness of the result; that can't be
right either.
I think it would be cleanest to make the addition operator always
return a non-const rvalue, regardless of whether the operands are
const. After all, the result is supposed to be freshly computed.
--
Summary: typeof(nonconst+const) is const
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: minor
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: debian-gcc at lists dot debian dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13519
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/13519] typeof(nonconst+const) is const
2003-12-30 13:18 [Bug c/13519] New: typeof(nonconst+const) is const debian-gcc at lists dot debian dot org
@ 2003-12-30 18:02 ` pinskia at gcc dot gnu dot org
2004-01-18 8:18 ` dhazeghi at yahoo dot com
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-30 18:02 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-12-30 17:56 -------
typeof just returns the type of the tree which it is bound to, so it looks like the front-end is getting
the type wrong.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13519
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/13519] typeof(nonconst+const) is const
2003-12-30 13:18 [Bug c/13519] New: typeof(nonconst+const) is const debian-gcc at lists dot debian dot org
2003-12-30 18:02 ` [Bug c/13519] " pinskia at gcc dot gnu dot org
@ 2004-01-18 8:18 ` dhazeghi at yahoo dot com
2004-05-28 10:16 ` pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: dhazeghi at yahoo dot com @ 2004-01-18 8:18 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From dhazeghi at yahoo dot com 2004-01-18 08:18 -------
Confirmed with 3.4 branch/mainline.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Keywords| |diagnostic
Last reconfirmed|0000-00-00 00:00:00 |2004-01-18 08:18:12
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13519
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/13519] typeof(nonconst+const) is const
2003-12-30 13:18 [Bug c/13519] New: typeof(nonconst+const) is const debian-gcc at lists dot debian dot org
2003-12-30 18:02 ` [Bug c/13519] " pinskia at gcc dot gnu dot org
2004-01-18 8:18 ` dhazeghi at yahoo dot com
@ 2004-05-28 10:16 ` pinskia at gcc dot gnu dot org
2004-06-06 15:22 ` cvs-commit at gcc dot gnu dot org
2004-06-06 15:51 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-28 10:16 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-05-27 18:44 -------
More to the point, now that the warnings are turned into errors in 3.4.0 and the mainline. I think the
problem is that the C front-end is taking the left side of the tree for the type.
--
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed|2004-01-18 08:18:12 |2004-05-27 18:44:12
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13519
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/13519] typeof(nonconst+const) is const
2003-12-30 13:18 [Bug c/13519] New: typeof(nonconst+const) is const debian-gcc at lists dot debian dot org
` (2 preceding siblings ...)
2004-05-28 10:16 ` pinskia at gcc dot gnu dot org
@ 2004-06-06 15:22 ` cvs-commit at gcc dot gnu dot org
2004-06-06 15:51 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-06-06 15:22 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From cvs-commit at gcc dot gnu dot org 2004-06-06 15:22 -------
Subject: Bug 13519
CVSROOT: /cvs/gcc
Module name: gcc
Changes by: jsm28@gcc.gnu.org 2004-06-06 15:21:59
Modified files:
gcc : ChangeLog c-decl.c c-tree.h c-typeck.c
gcc/testsuite : ChangeLog
Added files:
gcc/testsuite/gcc.c-torture/execute: enum-3.c
gcc/testsuite/gcc.dg: pr13519-1.c
Log message:
PR c/13519
* c-typeck.c (composite_type, common_pointer_type): New functions.
(common_type): Split parts into composite_type and
common_pointer_type. Ensure that arithmetic operations return
unqualified types without attributes. Don't make composite type
of signed enum and compatible integer be unsigned.
(build_conditional_expr, build_binary_op): Use
common_pointer_type.
* c-decl.c (merge_decls): Use composite_type.
* c-tree.h (composite_type): Declare.
testsuite:
* gcc.c-torture/enum-3.c, gcc.dg/pr13519-1.c: New tests.
Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.3853&r2=2.3854
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&r1=1.504&r2=1.505
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-tree.h.diff?cvsroot=gcc&r1=1.147&r2=1.148
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&r1=1.308&r2=1.309
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3812&r2=1.3813
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/enum-3.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr13519-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13519
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/13519] typeof(nonconst+const) is const
2003-12-30 13:18 [Bug c/13519] New: typeof(nonconst+const) is const debian-gcc at lists dot debian dot org
` (3 preceding siblings ...)
2004-06-06 15:22 ` cvs-commit at gcc dot gnu dot org
@ 2004-06-06 15:51 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-06 15:51 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-06-06 15:51 -------
Fixed in 3.5.0
--
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
Target Milestone|--- |3.5.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13519
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2004-06-06 15:51 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-30 13:18 [Bug c/13519] New: typeof(nonconst+const) is const debian-gcc at lists dot debian dot org
2003-12-30 18:02 ` [Bug c/13519] " pinskia at gcc dot gnu dot org
2004-01-18 8:18 ` dhazeghi at yahoo dot com
2004-05-28 10:16 ` pinskia at gcc dot gnu dot org
2004-06-06 15:22 ` cvs-commit at gcc dot gnu dot org
2004-06-06 15:51 ` pinskia 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).