------- Comment #2 from bonzini at gnu dot org 2006-08-07 07:38 ------- This gives an ICE-on-invalid.
template<int i> struct A { char d[i]; char &operator [] ( int indx ) { return d[indx]; } }; struct B { A<44> a; }; int main() { return __builtin_offsetof(B, a[0]); } Here, fold_offsetof_1 does not expect a CALL_EXPR to be there and dies. The reason for the reporter's bug is similar but we do not ICE because we have another INDIRECT_REF because of dereferencing the "char&" reference, and the tree is like INDIRECT_REF( CALL_EXPR ( operator[], INDIRECT_REF(null), 0 ) ) fold_offsetof_1 does not expect anything inside the INDIRECT_REF, and blindly returns 0. Testing a patch. -- bonzini at gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- AssignedTo|unassigned at gcc dot gnu |bonzini at gnu dot org |dot org | Status|NEW |ASSIGNED Last reconfirmed|2006-08-06 22:12:50 |2006-08-07 07:38:41 date| | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28573