------- Comment #24 from jakub at gcc dot gnu dot org 2010-06-28 11:05 ------- On: extern "C" void abort ();
struct S { int x; int y; }; struct T { int x; int y; T (int u, int v) : x (u), y (v) {} }; extern const S s; extern const T t, u; int sx = s.x; int tx = t.x; const S s = { 1, 2 }; const T t (1, 2); const T u (1, 2); int ux = u.x; int main () { if (sx != 1 || tx != 0 || ux != 1) abort (); if (s.x != 1 || s.y != 2) abort (); if (t.x != 1 || t.y != 2) abort (); if (u.x != 1 || u.y != 2) abort (); return 0; } it is easy to spot whether this optimization would be possible or not by looking at TREE_USED of the decl at check_initializer time. It is set for t (and s), but cleared for u. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=4131