| 1 |
// { dg-do assemble } |
| 2 |
// PRMS Id: 9127 |
| 3 |
// Bug: members of anonymous unions are not access-controlled. |
| 4 |
|
| 5 |
#include <stdio.h> |
| 6 |
|
| 7 |
struct Foo { |
| 8 |
public: |
| 9 |
union { |
| 10 |
long A; |
| 11 |
void *pX; |
| 12 |
}; |
| 13 |
union X { |
| 14 |
long A; |
| 15 |
void *pX; |
| 16 |
} PUB ; |
| 17 |
int PUB_A; |
| 18 |
protected: |
| 19 |
union { |
| 20 |
long B; // { dg-message "" } protected |
| 21 |
void *pY; // { dg-message "" } protected |
| 22 |
} ; |
| 23 |
union Y { |
| 24 |
long B; |
| 25 |
void *pY; |
| 26 |
} PRT; // { dg-message "" } protected |
| 27 |
int PRT_A; // { dg-message "" } protected |
| 28 |
private: |
| 29 |
union { |
| 30 |
long C; // { dg-message "" } private |
| 31 |
void *pZ; // { dg-message "" } private |
| 32 |
}; |
| 33 |
union Z { |
| 34 |
long C; |
| 35 |
void *pZ; |
| 36 |
} PRV; // { dg-message "" } private |
| 37 |
int PRV_A; // { dg-message "" } private |
| 38 |
}; |
| 39 |
|
| 40 |
struct Bar : public Foo { |
| 41 |
public: |
| 42 |
void DoSomething() { |
| 43 |
PUB_A = 0; |
| 44 |
Foo::A = 0; |
| 45 |
printf("%x\n",pX); |
| 46 |
Foo::PUB.A = 0; |
| 47 |
printf("%x\n",PUB.pX); |
| 48 |
B = 0; |
| 49 |
printf("%x\n",Foo::pY); |
| 50 |
PRT_A = 0; |
| 51 |
PRT.B = 0; |
| 52 |
printf("%x\n",Foo::PRT.pY); |
| 53 |
PRV_A = 0; // { dg-error "" } |
| 54 |
Foo::C = 0; // { dg-error "" } |
| 55 |
printf("%x\n",pZ); // { dg-error "" } |
| 56 |
Foo::PRV.C = 0; // { dg-error "" } |
| 57 |
printf("%x\n",PRV.pZ); // { dg-error "" } |
| 58 |
} |
| 59 |
}; |
| 60 |
|
| 61 |
int main() |
| 62 |
{ |
| 63 |
Foo a; |
| 64 |
|
| 65 |
a.PUB_A = 0; |
| 66 |
a.A = 0; |
| 67 |
printf("%x\n",a.pX); |
| 68 |
a.PRT_A = 0; // { dg-error "" } |
| 69 |
a.B = 0; // { dg-error "" } |
| 70 |
printf("%x\n",a.pY); // { dg-error "" } |
| 71 |
a.PRV_A = 0; // { dg-error "" } |
| 72 |
a.C = 0; // { dg-error "" } |
| 73 |
printf("%x\n",a.pZ); // { dg-error "" } |
| 74 |
a.PUB.A = 0; |
| 75 |
printf("%x\n",a.PUB.pX); |
| 76 |
a.PRT.B = 0; // { dg-error "" } |
| 77 |
printf("%x\n",a.PRT.pY); // { dg-error "" } |
| 78 |
a.PRV.C = 0; // { dg-error "" } |
| 79 |
printf("%x\n",a.PRV.pZ); // { dg-error "" } |
| 80 |
} |