Access to static protected member from friends of derived classes.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Access to static protected member from friends of derived classes.

Olivier Goffart
Hi,

A few years ago, I was trying to fix the bug 6840 [1] that relates to access to
static protected member from friends of derived classes.

I made a patch that fixes it at the time, but it was rejected because this was
considered as a drafting error in the standard [2].

Recently, I attended a talk by a Debian dev who tried to compile all debian
packages with clang. And that bug was one frequent cause of compilation error.
[3]

I was wondering if it was not time to revisit the decision, and consider that
this issue should be fixed after all.

The problem is the following:

class N { protected: static int m; };
class P : public N { friend class R; };
class R {
  int foo() {
     return N::m; // should work because the access is given via P.
    // but clang gives an error:
    // error: 'm' is a protected member of 'N'
  }
};

C++11 ยง11.4  explicitly states this is permitted, with an example. And gcc
supports that fine.

Opinions?
--
Olivier

[1] http://llvm.org/bugs/show_bug.cgi?id=6840
[2] http://lists.cs.uiuc.edu/pipermail/cfe-dev/2010-June/009310.html
[3] http://sylvestre.ledru.info/blog/media/5/rebuild-debian-presentation-clang-July-10.pdf  (slide 35)

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Access to static protected member from friends of derived classes.

John McCall
On Feb 14, 2013, at 7:11 AM, Olivier Goffart <[hidden email]> wrote:
> A few years ago, I was trying to fix the bug 6840 [1] that relates to access to
> static protected member from friends of derived classes.
>
> I made a patch that fixes it at the time, but it was rejected because this was
> considered as a drafting error in the standard [2].

More a defect than a drafting error, really.  I acknowledge that there's an
explicit example in the standard.  I just think that the standard is mistaken
to permit this, for the reasons already enumerated and some new ones.

Notable among the new ones is that the implicit dependence on a totally
unrelated declaration would be a major burden on any serious modules
proposal.

John.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Access to static protected member from friends of derived classes.

Michael Marcin
Is there a workaround? I have code compiling on g++ that relies upon this behavior and I'm trying to get it to work on Clang.