Created attachment 60812 [details] reproducer compiling as g++ -O2 results in static initialization and folding. Compilng as g++ -O2 -DBUG results in dynamic init for BAR, but static init for FOO: _GLOBAL__sub_I__Z3foov: movq $16, _ZL3BAR(%rip) ret _Z3foov: movl 16, %eax ret _Z3barv: movq _ZL3BAR(%rip), %rax movl (%rax), %eax ret The problem is that we end up n initializer_constant_valid_p (varasm.cc), which I think expects fully folded expressions. When analyzing BAR's initializer it recurses into FOO's DECL_INITIAL, which is essentially (+ 16 (* 16 0)), and because of the multiplier thinks it's not suitable for a constant init. For some reason we don't make that mistake with FOO itself. I suspect we need to store a more folded initializer in DECL_INITIAL? The original code had the multiplier as 2, not zero BTW.
Confirmed. I have an idea on how to fix this, similar to PR 4131 .