Skip to content

Can't access anonymous structs in base class through derived class #158131

@cjdb

Description

@cjdb

Given

struct Base {
  int b;
  struct {
    int x;
  };
};

struct Derived : public Base {
  int d;
};

int main() {
  Derived d;
  d.b = 1;
  d.x = 2;
  d.d = 3;
  return 0;
}

it should be possible to do this in LLDB

(lldb) break 17
(lldb) r
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> d = lldb.frame.EvaluateExpression("d")
>>> d.GetChildMemberWithName("b")
(int) b = 1
>>> d.GetChildMemberWithName("x")
(int) x = 2

We end up getting

>>> d.GetChildMemberWithName("x")
No value

After some poking around, we've worked out that LLDB permits accessing base class members from a derived class, anonymous struct members from the enclosing class, but not a base class' anonymous struct members from a derived class. Since C++ permits this, it would be good for LLDB to support it too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions