Enough already with the KDE bug!

Martin von Loewis martin@mira.isdn.cs.tu-berlin.de
Sun Mar 29 14:03:00 GMT 1998


I've been reviewing a conversation on the code shown below. I was told
at the time that egcs is right and KDE/glibc is wrong; I now find
that this is not correct.

class X{
    unsigned int i;
  public:
    void f();
};

void X::f()
{
  int j=
  (__extension__ ({ union { __typeof(i) __in; int __i; } __u;
                            __u.__in = (i); __u.__i;}));
}

The code in question was similar to the one shown above. The error
message is

a.cc:10: member `i' is a private member of class `X'

It was argued that __typeof is similar to sizeof, and therefore the
same access control should be applied. So far so good.

It seems to me that the union is a local class as described in
[class.local]. In that section, the standard says

  A class can be defined within a function definition; such a class is
  called a local class. The name of a local class is local to its
  enclosing scope. The local class is in the scope of the enclosing
  scope, and has the same access to names outside the function as does
  the enclosing function.

Since `i'is a name outside the member function, the local class can
access it since the function can. So `i' should be accessible, even
though it is private.

What do you think?

Martin



More information about the Gcc-bugs mailing list