public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/15471] New: Incorrect member pointer offsets in anonymous structs/unions
@ 2004-05-16 22:56 us15 at os dot inf dot tu-dresden dot de
2004-05-16 23:06 ` [Bug c++/15471] " pinskia at gcc dot gnu dot org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: us15 at os dot inf dot tu-dresden dot de @ 2004-05-16 22:56 UTC (permalink / raw)
To: gcc-bugs
The code below outputs the addresses of member variables of class "myclass"
using a table of pointers to member variables and using an instance of
"myclass". I'd expect both methods to produce the same result, however, the
addresses of member variables x and y are wrong when applying the member
pointers to object "foo".
Compiler version:
Reading specs from /usr/lib/gcc/i486-slackware-linux/3.4.0/specs
Configured with: ../gcc-3.4.0/configure --prefix=/usr --enable-shared
--enable-threads=posix --enable-__cxa_atexit --disable-checking --with-gnu-ld
--verbose --target=i486-slackware-linux --host=i486-slackware-linux
Thread model: posix
gcc version 3.4.0
Example code to demonstrate the problem:
#include <stdio.h>
class myclass
{
public:
union
{
unsigned state[5];
struct
{
unsigned a;
unsigned b;
union
{
unsigned nums[2];
struct
{
unsigned x, y;
};
};
unsigned c;
};
};
};
unsigned
myclass::*
members[] = {
&myclass::a,
&myclass::b,
&myclass::x,
&myclass::y,
&myclass::c,
};
myclass
foo;
int
main (void)
{
printf ("a -> %p %p\n", &(foo.*members[0]), &foo.a);
printf ("b -> %p %p\n", &(foo.*members[1]), &foo.b);
printf ("x -> %p %p\n", &(foo.*members[2]), &foo.x); // differs
printf ("y -> %p %p\n", &(foo.*members[3]), &foo.y); // differs
printf ("c -> %p %p\n", &(foo.*members[4]), &foo.c);
return 0;
}
--
Summary: Incorrect member pointer offsets in anonymous
structs/unions
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: us15 at os dot inf dot tu-dresden dot de
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: n/a
GCC host triplet: i486-slackware-linux
GCC target triplet: i486-slackware-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15471
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/15471] Incorrect member pointer offsets in anonymous structs/unions
2004-05-16 22:56 [Bug c++/15471] New: Incorrect member pointer offsets in anonymous structs/unions us15 at os dot inf dot tu-dresden dot de
@ 2004-05-16 23:06 ` pinskia at gcc dot gnu dot org
2004-05-26 11:40 ` bangerth at dealii dot org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-16 23:06 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-05-15 21:56 -------
anonymous structs are an extension to c++ so they could act any way.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15471
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/15471] Incorrect member pointer offsets in anonymous structs/unions
2004-05-16 22:56 [Bug c++/15471] New: Incorrect member pointer offsets in anonymous structs/unions us15 at os dot inf dot tu-dresden dot de
2004-05-16 23:06 ` [Bug c++/15471] " pinskia at gcc dot gnu dot org
@ 2004-05-26 11:40 ` bangerth at dealii dot org
2004-05-26 18:49 ` [Bug c++/15471] [3.4/3.5 Regression] " giovannibajo at libero dot it
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: bangerth at dealii dot org @ 2004-05-26 11:40 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-05-25 14:20 -------
I don't know what we're supposed to do here, but this is indeed
surprising:
-----------------------
#include <stdio.h>
struct myclass {
unsigned a;
union {
unsigned x;
};
};
int main () {
myclass foo;
unsigned myclass::* member = &myclass::x;
printf ("x -> %p %p\n", &(foo.*member), &foo.x);
}
-----------------------
One would expect the two pointers to be the same, but they're not:
g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ x.cc ; ./a.out
x -> 0xbfffeaa0 0xbfffeaa4
It has indeed to do with the anonymous union (which in this case only
contains a single element), since if I remove it and bring the variable
x to the myclass scope, then the problem disappears.
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15471
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/15471] [3.4/3.5 Regression] Incorrect member pointer offsets in anonymous structs/unions
2004-05-16 22:56 [Bug c++/15471] New: Incorrect member pointer offsets in anonymous structs/unions us15 at os dot inf dot tu-dresden dot de
2004-05-16 23:06 ` [Bug c++/15471] " pinskia at gcc dot gnu dot org
2004-05-26 11:40 ` bangerth at dealii dot org
@ 2004-05-26 18:49 ` giovannibajo at libero dot it
2004-05-29 15:32 ` mmitchel at gcc dot gnu dot org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: giovannibajo at libero dot it @ 2004-05-26 18:49 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From giovannibajo at libero dot it 2004-05-26 12:07 -------
I couldn't find the relevant paragraph in the standard, thus I am not sure this
is actually legal code. It must be noted that EDG in strict mode accepts it and
generates the same address for both pointers (which is by no doubt the correct
behaviour, once we assume the code is legal).
GCC rejects this snippet up to 3.4. Since 3.4, we accept the snippet but
generate wrong code with it. I rate this as a regression nonetheless, since
wrong-code is much worse than what we used to do.
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |giovannibajo at libero dot
| |it
Severity|normal |critical
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Keywords| |wrong-code
Known to fail| |2.95.3 3.0.4 3.3.3 3.4.0
| |3.5.0
Last reconfirmed|0000-00-00 00:00:00 |2004-05-26 12:07:55
date| |
Summary|Incorrect member pointer |[3.4/3.5 Regression]
|offsets in anonymous |Incorrect member pointer
|structs/unions |offsets in anonymous
| |structs/unions
Target Milestone|--- |3.4.1
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15471
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/15471] [3.4/3.5 Regression] Incorrect member pointer offsets in anonymous structs/unions
2004-05-16 22:56 [Bug c++/15471] New: Incorrect member pointer offsets in anonymous structs/unions us15 at os dot inf dot tu-dresden dot de
` (2 preceding siblings ...)
2004-05-26 18:49 ` [Bug c++/15471] [3.4/3.5 Regression] " giovannibajo at libero dot it
@ 2004-05-29 15:32 ` mmitchel at gcc dot gnu dot org
2004-05-30 2:01 ` cvs-commit at gcc dot gnu dot org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2004-05-29 15:32 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |mark at codesourcery dot com
|dot org |
Status|NEW |ASSIGNED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15471
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/15471] [3.4/3.5 Regression] Incorrect member pointer offsets in anonymous structs/unions
2004-05-16 22:56 [Bug c++/15471] New: Incorrect member pointer offsets in anonymous structs/unions us15 at os dot inf dot tu-dresden dot de
` (3 preceding siblings ...)
2004-05-29 15:32 ` mmitchel at gcc dot gnu dot org
@ 2004-05-30 2:01 ` cvs-commit at gcc dot gnu dot org
2004-05-30 3:48 ` cvs-commit at gcc dot gnu dot org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-05-30 2:01 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From cvs-commit at gcc dot gnu dot org 2004-05-28 22:29 -------
Subject: Bug 15471
CVSROOT: /cvs/gcc
Module name: gcc
Branch: gcc-3_4-branch
Changes by: mmitchel@gcc.gnu.org 2004-05-28 22:29:44
Modified files:
gcc/cp : ChangeLog decl2.c init.c name-lookup.c typeck.c
gcc/testsuite : ChangeLog
Added files:
gcc/testsuite/g++.dg/expr: ptrmem4.C
gcc/testsuite/g++.dg/template: operator3.C
gcc/testsuite/g++.dg/warn: noeffect5.C
Log message:
PR c++/15083
* decl2.c (delete_sanity): Set TREE_SIDE_EFFECTS on a DELETE_EXPR,
even in a templat.e
* init.c (build_new): Likewise.
PR c++/15640
* name-lookup.c (arg_assoc): Robustify.
PR c++/15471
* typeck.c (unary_complex_lvalue): Use context_for_name_lookup
when determining the scope to use for a pointer to member.
PR c++/15083
* g++.dg/warn/noeffect5.C: New test.
PR c++/15471
* g++.dg/expr/ptrmem4.C: New test.
PR c++/15640
* g++.dg/template/operator3.C: New test.
Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.107&r2=1.3892.2.108
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.695.4.7&r2=1.695.4.8
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.356.2.9&r2=1.356.2.10
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.34.2.12&r2=1.34.2.13
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.519.2.16&r2=1.519.2.17
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.185&r2=1.3389.2.186
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/expr/ptrmem4.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/operator3.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/warn/noeffect5.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.2.4.1
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15471
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/15471] [3.4/3.5 Regression] Incorrect member pointer offsets in anonymous structs/unions
2004-05-16 22:56 [Bug c++/15471] New: Incorrect member pointer offsets in anonymous structs/unions us15 at os dot inf dot tu-dresden dot de
` (4 preceding siblings ...)
2004-05-30 2:01 ` cvs-commit at gcc dot gnu dot org
@ 2004-05-30 3:48 ` cvs-commit at gcc dot gnu dot org
2004-05-30 5:12 ` cvs-commit at gcc dot gnu dot org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-05-30 3:48 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From cvs-commit at gcc dot gnu dot org 2004-05-28 22:35 -------
Subject: Bug 15471
CVSROOT: /cvs/gcc
Module name: gcc
Changes by: mmitchel@gcc.gnu.org 2004-05-28 22:35:50
Modified files:
gcc/cp : ChangeLog decl2.c init.c name-lookup.c typeck.c
gcc/testsuite : ChangeLog
Added files:
gcc/testsuite/g++.dg/expr: ptrmem4.C
gcc/testsuite/g++.dg/template: operator3.C
gcc/testsuite/g++.dg/warn: noeffect6.C
Log message:
PR c++/15083
* decl2.c (delete_sanity): Set TREE_SIDE_EFFECTS on a DELETE_EXPR,
even in a templat.e
* init.c (build_new): Likewise.
PR c++/15640
* name-lookup.c (arg_assoc): Robustify.
PR c++/15471
* typeck.c (unary_complex_lvalue): Use context_for_name_lookup
when determining the scope to use for a pointer to member.
PR c++/15083
* g++.dg/warn/noeffect5.C: New test.
PR c++/15471
* g++.dg/expr/ptrmem4.C: New test.
PR c++/15640
* g++.dg/template/operator3.C: New test.
Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4064&r2=1.4065
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&r1=1.709&r2=1.710
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&r1=1.370&r2=1.371
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&r1=1.54&r2=1.55
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.544&r2=1.545
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3789&r2=1.3790
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/expr/ptrmem4.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/operator3.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/warn/noeffect6.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15471
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/15471] [3.4/3.5 Regression] Incorrect member pointer offsets in anonymous structs/unions
2004-05-16 22:56 [Bug c++/15471] New: Incorrect member pointer offsets in anonymous structs/unions us15 at os dot inf dot tu-dresden dot de
` (5 preceding siblings ...)
2004-05-30 3:48 ` cvs-commit at gcc dot gnu dot org
@ 2004-05-30 5:12 ` cvs-commit at gcc dot gnu dot org
2004-05-30 5:44 ` cvs-commit at gcc dot gnu dot org
2004-05-30 10:53 ` mmitchel at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-05-30 5:12 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From cvs-commit at gcc dot gnu dot org 2004-05-28 23:33 -------
Subject: Bug 15471
CVSROOT: /cvs/gcc
Module name: gcc
Branch: gcc-3_4-branch
Changes by: mmitchel@gcc.gnu.org 2004-05-28 23:33:40
Modified files:
gcc/cp : ChangeLog cp-tree.h expr.c typeck.c
Log message:
PR c++/15471
* typeck.c (unary_complex_lvalue): Use context_for_name_lookup
when determining the scope to use for a pointer to member.
(lookup_anon_field): Give it external linkage.
* cp-tree.h (lookup_anon_field): Declare it.
* expr.c (cplus_expand_constant): Use it.
Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.108&r2=1.3892.2.109
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.946.4.11&r2=1.946.4.12
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/expr.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.75.4.1&r2=1.75.4.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.519.2.17&r2=1.519.2.18
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15471
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/15471] [3.4/3.5 Regression] Incorrect member pointer offsets in anonymous structs/unions
2004-05-16 22:56 [Bug c++/15471] New: Incorrect member pointer offsets in anonymous structs/unions us15 at os dot inf dot tu-dresden dot de
` (6 preceding siblings ...)
2004-05-30 5:12 ` cvs-commit at gcc dot gnu dot org
@ 2004-05-30 5:44 ` cvs-commit at gcc dot gnu dot org
2004-05-30 10:53 ` mmitchel at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-05-30 5:44 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From cvs-commit at gcc dot gnu dot org 2004-05-28 23:34 -------
Subject: Bug 15471
CVSROOT: /cvs/gcc
Module name: gcc
Changes by: mmitchel@gcc.gnu.org 2004-05-28 23:34:39
Modified files:
gcc/cp : ChangeLog cp-tree.h expr.c typeck.c
Log message:
PR c++/15471
* typeck.c (unary_complex_lvalue): Use context_for_name_lookup
when determining the scope to use for a pointer to member.
(lookup_anon_field): Give it external linkage.
* cp-tree.h (lookup_anon_field): Declare it.
* expr.c (cplus_expand_constant): Use it.
Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4065&r2=1.4066
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&r1=1.968&r2=1.969
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/expr.c.diff?cvsroot=gcc&r1=1.77&r2=1.78
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.545&r2=1.546
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15471
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/15471] [3.4/3.5 Regression] Incorrect member pointer offsets in anonymous structs/unions
2004-05-16 22:56 [Bug c++/15471] New: Incorrect member pointer offsets in anonymous structs/unions us15 at os dot inf dot tu-dresden dot de
` (7 preceding siblings ...)
2004-05-30 5:44 ` cvs-commit at gcc dot gnu dot org
@ 2004-05-30 10:53 ` mmitchel at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2004-05-30 10:53 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From mmitchel at gcc dot gnu dot org 2004-05-28 23:35 -------
Fixed in GCC 3.4.1.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15471
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2004-05-28 23:35 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-16 22:56 [Bug c++/15471] New: Incorrect member pointer offsets in anonymous structs/unions us15 at os dot inf dot tu-dresden dot de
2004-05-16 23:06 ` [Bug c++/15471] " pinskia at gcc dot gnu dot org
2004-05-26 11:40 ` bangerth at dealii dot org
2004-05-26 18:49 ` [Bug c++/15471] [3.4/3.5 Regression] " giovannibajo at libero dot it
2004-05-29 15:32 ` mmitchel at gcc dot gnu dot org
2004-05-30 2:01 ` cvs-commit at gcc dot gnu dot org
2004-05-30 3:48 ` cvs-commit at gcc dot gnu dot org
2004-05-30 5:12 ` cvs-commit at gcc dot gnu dot org
2004-05-30 5:44 ` cvs-commit at gcc dot gnu dot org
2004-05-30 10:53 ` mmitchel 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).