public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/66341] New: Some casts wrongly produce a lvalue
@ 2015-05-30 8:24 kp.lehrmann+gcc at gmail dot com
2015-05-30 16:31 ` [Bug c/66341] " msebor at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: kp.lehrmann+gcc at gmail dot com @ 2015-05-30 8:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66341
Bug ID: 66341
Summary: Some casts wrongly produce a lvalue
Product: gcc
Version: 5.1.0
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: kp.lehrmann+gcc at gmail dot com
Target Milestone: ---
Created attachment 35653
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35653&action=edit
gcc compiles ok instead of producing a "error: lvalue required as left operand
of assignment"
Hello,
gcc (any version that I tried) allows some casts to produce a lvalue, whereas
"error: lvalue required as left operand of assignment" would be expected.
Basically, cast of the following form wrongly compile:
struct B{ int *c;};
struct A{ struct B b;};
struct A a;
int d = 5;
(int*)((struct A *)(&a)->b.c) = &d;
Note that if the first cast (int*) is replaced by a cast to any type but the
type of the member in struct B, the expected error message is produced.
For instance,
(char*)((struct A *)(&a)->b.c) = &d;
produce the expected error.
Best regards
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/66341] Some casts wrongly produce a lvalue
2015-05-30 8:24 [Bug c/66341] New: Some casts wrongly produce a lvalue kp.lehrmann+gcc at gmail dot com
@ 2015-05-30 16:31 ` msebor at gcc dot gnu.org
2015-06-03 16:20 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: msebor at gcc dot gnu.org @ 2015-05-30 16:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66341
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2015-05-30
CC| |msebor at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed with both gcc and g++ 5.1.0. Below is a slightly smaller test case
along with Clang output.
$ cat t.c && gcc -Wall -c t.c && clang t.c
struct A { int *i; };
void foo (struct A *a)
{
(int*)(struct A*)a->i = a->i;
}
t.c:5:27: error: expression is not assignable
(int*)(struct A*)a->i = a->i;
~~~~~~~~~~~~~~~~~~~~~ ^
1 error generated.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/66341] Some casts wrongly produce a lvalue
2015-05-30 8:24 [Bug c/66341] New: Some casts wrongly produce a lvalue kp.lehrmann+gcc at gmail dot com
2015-05-30 16:31 ` [Bug c/66341] " msebor at gcc dot gnu.org
@ 2015-06-03 16:20 ` mpolacek at gcc dot gnu.org
2015-06-04 8:18 ` mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-06-03 16:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66341
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
CC| |mpolacek at gcc dot gnu.org
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/66341] Some casts wrongly produce a lvalue
2015-05-30 8:24 [Bug c/66341] New: Some casts wrongly produce a lvalue kp.lehrmann+gcc at gmail dot com
2015-05-30 16:31 ` [Bug c/66341] " msebor at gcc dot gnu.org
2015-06-03 16:20 ` mpolacek at gcc dot gnu.org
@ 2015-06-04 8:18 ` mpolacek at gcc dot gnu.org
2015-06-04 8:18 ` mpolacek at gcc dot gnu.org
2023-03-23 1:23 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-06-04 8:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66341
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/66341] Some casts wrongly produce a lvalue
2015-05-30 8:24 [Bug c/66341] New: Some casts wrongly produce a lvalue kp.lehrmann+gcc at gmail dot com
` (2 preceding siblings ...)
2015-06-04 8:18 ` mpolacek at gcc dot gnu.org
@ 2015-06-04 8:18 ` mpolacek at gcc dot gnu.org
2023-03-23 1:23 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-06-04 8:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66341
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Author: mpolacek
Date: Thu Jun 4 08:17:45 2015
New Revision: 224115
URL: https://gcc.gnu.org/viewcvs?rev=224115&root=gcc&view=rev
Log:
PR c/66341
* c-typeck.c (build_c_cast): Wrap VALUE into NON_LVALUE_EXPR if
it is a lvalue.
* gcc.dg/lvalue-8.c: New test.
Added:
trunk/gcc/testsuite/gcc.dg/lvalue-8.c
Modified:
trunk/gcc/c/ChangeLog
trunk/gcc/c/c-typeck.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/66341] Some casts wrongly produce a lvalue
2015-05-30 8:24 [Bug c/66341] New: Some casts wrongly produce a lvalue kp.lehrmann+gcc at gmail dot com
` (3 preceding siblings ...)
2015-06-04 8:18 ` mpolacek at gcc dot gnu.org
@ 2023-03-23 1:23 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-03-23 1:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66341
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |6.0
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-03-23 1:23 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-30 8:24 [Bug c/66341] New: Some casts wrongly produce a lvalue kp.lehrmann+gcc at gmail dot com
2015-05-30 16:31 ` [Bug c/66341] " msebor at gcc dot gnu.org
2015-06-03 16:20 ` mpolacek at gcc dot gnu.org
2015-06-04 8:18 ` mpolacek at gcc dot gnu.org
2015-06-04 8:18 ` mpolacek at gcc dot gnu.org
2023-03-23 1:23 ` pinskia at gcc dot gnu.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).