Giter VIP home page Giter VIP logo

Comments (2)

zygoloid avatar zygoloid commented on July 2, 2024

The current rule is consistent with the rule for base classes:

struct a { int n; };
struct e {};
struct x : e {};
struct y : e {};
struct s1 : x, y, a {}; // sizeof(s1) == 4
struct s2 : a, x, y {}; // sizeof(s2) == 8

If we used the s1 layout for s2, then converting all of s2's base classes into [[no_unique_address]] members would change its layout.

So we need to decide which we care more about: that a sequence of bases can be transformed into a sequence of [[no_unique_address]] members with no change in layout (which we can only guarantee in the absence of dynamic base classes, due to the special layout rules for virtual bases and primary base classes), or that we don't waste space on empty [[no_unique_address]] members whenever possible.

Here is perhaps a more compelling example justifying the current approach:

struct noncopyable {};
struct alloc : noncopyable {};
struct base : noncopyable { int n; };
struct data : noncopyable { int k; };
struct z : base {
  [[no_unique_address]] alloc x;
  data m;
};

It is desirable for the layout of z to match the layout of

struct z : base, alloc {
  data m;
};

... but if we consider placing alloc at offsets that would not be considered for a base class, we cannot guarantee that.

Perhaps we could consider additional offsets only for [[no_unique_address]] members that do not occur as part of a sequence of such members at the start of a class, on the basis that such cases have no corresponding base class layout to be compatible with. (And I'll open a separate issue that we should consider more offsets for empty subobjects in general.)

from cxx-abi.

zygoloid avatar zygoloid commented on July 2, 2024

Filed #77 to capture that we should consider nonzero offsets within the class when performing EBO.

from cxx-abi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.