On Tue, Jul 22, 2014 at 09:17:12PM +0400, Alexander Monakov wrote: > On Tue, 22 Jul 2014, Alexander Monakov wrote: > > I'd like to push this topic forward a bit. I've bootstrapped and regtested > > a > > version of the patch based on the initial proposal to check DECL_WEAK. The > > approach with decl_replaceable_p looks not that easy; I'll expand in a > > followup email. > > The problem with the patch below using decl_replaceable_p is that it regresses > the following C++ testcase: > > struct z { > static const int aaa = 1; > }; > > //const int z::aaa; > > int foo(int x) > { > return x ? z::aaa : x; > } > > Here decl_replaceable_p is 'true' for z::aaa. With the patch the reference to > z::aaa is not folded, but its definition is not emitted either, so a undefined > reference error is produced at link time. But naturally > varpool_ctor_useable_for_folding_p for z::aaa must stay true in the first > place. > > In a way z::aaa is "replaceable" in the sense that the compiler is not going > to emit a definition, so if anything references z::aaa in the current > translation unit (if the address is taken), the definition must come from > another TU. Nevertheless, references to the value can be folded. I'm > unsure what the correct test would look like. Any advice?
Why is this considered "replaceable"? That sounds like a bug to me. Anyway, in looking for a solution, wouldn't it be helpful to look at how this was treated in 4.8 and earlier, before bug 61144 was introduced? Rich