[cfe-dev] Three code snippets accepted by clang and rejected by g++

John McCall rjmccall at apple.com
Mon Aug 11 13:31:08 PDT 2014

On Aug 10, 2014, at 5:26 PM, Nikola Smiljanic <popizdeh at gmail.com> wrote:
> I'd say the first one is a clang bug.

I agree.  This is poor language design — access should really be granted to all lexically nested code, not just members — but it’s what we’ve got.

> Friends are not transitive, the problem is in the implementation of class.protected restriction inside CheckAccess function.
>   EffectiveContext EC(S.CurContext);
> Current context here is class B and that doesn't seem right, added John as he's the author.

That seems wrong.  Are you just speculating?  The current context should be the declaration of ‘int f(B)’ that’s nested within the class.

I believe the correct fix is to change the special case for friend functions in the EffectiveContext constructor, probably by walking to the semantic context instead of the lexical context.  That is, removing the special case completely.  However, presumably that special case was added for a reason.


More information about the cfe-dev mailing list