Improving -Wunused-member-function

Peter Collingbourne peter at pcc.me.uk
Mon Mar 24 13:25:32 PDT 2014


On Sun, Mar 23, 2014 at 10:14:22PM -0000, Nuno Lopes wrote:
> The second part of the plan is to mark all methods described previously  
> (well, the used ones) with internal linkage. In my naive view it seems 
> fine, but is this legal per the standard?  I think it can be an important 
> optimization, since then LLVM can more freely inline and remove the 
> symbols altogether.

(moving the discussion over here)

On Mon, Mar 24, 2014 at 08:02:24PM -0000, Nuno Lopes wrote:
>> Would this be a legal transformation? What if the client uses a trick
>> such as the one described here to access a private member:
>> http://bloglitb.blogspot.com/2010/07/access-to-private-members-thats-easy.html
>
> Well, in that case a pointer to the private member is taken, so it should 
> be fine.
> Anyway, I would prefer if we had that discussion in the cfe ML, so that 
> the language laywers can chime in.  I'm not a C++ expert; I was just 
> curious why we are not exploiting private members/fields more 
> aggressively.

The reference may be taken in a translation unit other than the one which
holds the private members, and this reference would not be satisfied if the
private members are marked internal.

Perhaps this problem would be solved with a language rule that forbids explicit
instantiations from bypassing access controls unless the definition of the
referenced member is available.

Thanks,
-- 
Peter



More information about the cfe-commits mailing list