The following little code sample does no longer compile with 4.3 or higher: struct a {}; void b() { int a::*m; a *c; int p = reinterpret_cast<char*>(&(c->*m)) - reinterpret_cast<char*>(c); } Instead the compiler emits the error message: bad.cc: In function ‘void b()’: bad.cc:5: error: aggregate value used where an integer was expected Though it is clear that this code sample is not perfectly valid according to the C++ standard since "reinterpret_cast<char*>(&(c->*m))" and "reinterpret_cast<char*>(c)" are not part of the same array I would not expect this kind of behavior since the claim of the compiler that there is something wrong with types is completely bogus. Rewriting the code like the following makes the compiler accepting it again: struct a {}; void b() { int a::*m; a *c; char* d = reinterpret_cast<char*>(&(c->*m)); char* e = reinterpret_cast<char*>(c); int p = d - e; }
This works for me with 4.3.2 and the current trunk. Does it work for you?
It works for you? This is weired! Just tried it with current trunk again and it does still show exactly the same error there.
Ok, it fails with -m64, looking into it. Confirmed.
Some folding optimizing is changing "reinterpret_cast<char*>(&(c->*m)) - reinterpret_cast<char*>(c)" into (long int)(m) and then we have an implicit conversion into int: return convert (type, get_unwidened (TREE_OPERAND (expr, 0), type));
I have a simple fix, the front-end should have already warned about the conversion from a pointer to a member object to an integer type. Therefor convert can handle OFFSET_TYPE just like INTEGER_TYPE and such.
GCC 4.3.3 is being released, adjusting target milestone.
ping?
Subject: Re: [4.3/4.4 Regression] Incorrect type diagnostic on substracting casted char pointers Sent from my iPhone On Feb 3, 2009, at 5:56 AM, "bonzini at gnu dot org" <gcc-bugzilla@gcc.gnu.org > wrote: > > > ------- Comment #7 from bonzini at gnu dot org 2009-02-03 13:56 > ------- > ping? The patch was just approved last night and I will be applying it when I get into work today. > > > > -- > > bonzini at gnu dot org changed: > > What |Removed |Added > --- > --- > ---------------------------------------------------------------------- > CC| |bonzini at gnu dot org > > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36607 >
Subject: Bug 36607 Author: pinskia Date: Tue Feb 3 22:38:16 2009 New Revision: 143909 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=143909 Log: 2009-02-03 Andrew Pinski <andrew_pinski@playstation.sony.com> PR C++/36607 * convert.c (convert_to_integer): Treat OFFSET_TYPE like INTEGER_TYPE. 2009-02-03 Andrew Pinski <andrew_pinski@playstation.sony.com> PR C++/36607 * g++.dg/expr/cast10.C: New test. Added: trunk/gcc/testsuite/g++.dg/expr/cast10.C Modified: trunk/gcc/ChangeLog trunk/gcc/convert.c trunk/gcc/testsuite/ChangeLog
Fixed on the trunk at least.
I am no longer working on this one.
Testing a backport.
Subject: Bug 36607 Author: rguenth Date: Fri Jun 19 21:44:24 2009 New Revision: 148730 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148730 Log: 2009-06-19 Richard Guenther <rguenther@suse.de> Backport from mainline: 2009-02-03 Andrew Pinski <andrew_pinski@playstation.sony.com> PR C++/36607 * convert.c (convert_to_integer): Treat OFFSET_TYPE like INTEGER_TYPE. * g++.dg/expr/cast10.C: New test. 2009-02-03 Jakub Jelinek <jakub@redhat.com> PR target/35318 * function.c (match_asm_constraints_1): Skip over initial optional % in the constraint. * gcc.c-torture/compile/pr35318.c: New test. 2009-05-20 Jakub Jelinek <jakub@redhat.com> PR middle-end/40204 * fold-const.c (fold_binary) <case BIT_AND_EXPR>: Avoid infinite recursion if build_int_cst_type returns the same INTEGER_CST as arg1. * gcc.c-torture/compile/pr40204.c: New test. Added: branches/gcc-4_3-branch/gcc/testsuite/g++.dg/expr/cast10.C branches/gcc-4_3-branch/gcc/testsuite/gcc.c-torture/compile/pr35318.c branches/gcc-4_3-branch/gcc/testsuite/gcc.c-torture/compile/pr40204.c Modified: branches/gcc-4_3-branch/gcc/ChangeLog branches/gcc-4_3-branch/gcc/convert.c branches/gcc-4_3-branch/gcc/fold-const.c branches/gcc-4_3-branch/gcc/function.c branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
Fixed.