Compiling the code below with -O2 -Wall produces the buggy warning mentionned in the subject. g++ 4.1 and 4.3 do not have this problem. The code below is pretty minimal (extracted from CGAL). For example, removing the derivation from the Empty_class removes the buggy warning. ---------------- struct Empty_class {}; struct C : Empty_class {}; struct M { static C f() { return C(); } }; struct R { C c; R() : c(M::f()) {} }; int main() { R r; return 0; } --------------------
int main() () { struct Empty_class * this.0; struct Empty_class * const this; struct C * D.2077; struct R r; int D.2064; <bb 2>: D.2077_1 = &r.c; this.0_3 = this.0_2; this.0_4 = (struct Empty_class *) D.2077_1; D.2064_5 = 0; return D.2064_5; } somehow inlining ends up with the unused copies.
This works in GCC 4.1, 4.3 and 4.4, so this is either a regression (that probably will not be fixed before 4.2 is closed) or it is not a regression and should be closed as FIXED already in trunk.
Closing 4.2 branch, fixed in 4.3.