When declaring an anonymous union inside a class,
any variable from an anonymous struct contained in the union is accessible 
like a public member, regardless of the access level of the enclosing union.

Bug does only occur when struct and union are BOTH anonymous.

The following sample code, which violates access level, compiles under gcc
3.3.6, 3.4.5 debian prerelease and gcc 4.0.2.

Expected result: gcc should report access level violation.

---- testcase ----

class foo {
private:
  union {
    struct {
      int should_be_private;
    };
  };
};

int main()
{
  foo test;
  test.should_be_private = 1;
}


-- 
           Summary: gcc ignores access level violation: struct variables in
                    anonymous union accessible as public
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gcc at warped-space dot de
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24926

Reply via email to