This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/68161] New: Inconsistent behaviour of unnamed field with inheritance.


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68161

            Bug ID: 68161
           Summary: Inconsistent behaviour of unnamed field with
                    inheritance.
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gpderetta at gmail dot com
  Target Milestone: ---

As an extension to C++, g++ allows the following:

struct B {
        struct { int bar; };
};

int main()
{
        B foo;
        (void)foo.bar; // ok
}

The following does not work though:

struct A {
        int bar;
};

struct B {
        struct : A {};
};

int main()
{

        B foo;
        (void)foo.bar;  // error: 'struct B' has no member named 'bar'
}

As unnamed struct fields are an extension, this is not really a bug as g++ can
do whatever it wants, but it does seems inconsistent. 

The expected behaviour is useful to inject arbitrary names as members.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]