[llvm-bugs] [Bug 49758] New: no_unique_address non-static data member doesn't make class non-POD for the purpose of layout

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Mar 29 07:01:50 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=49758

            Bug ID: 49758
           Summary: no_unique_address non-static data member doesn't make
                    class non-POD for the purpose of layout
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: leni536 at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

Version: clang version 13.0.0 (https://github.com/llvm/llvm-project.git
aaab4441796909e1b9cf4279906a56350c8fade7)

Compiler flags: -std=C++20

Consider the following:

```
struct alignas(2) A { char ch1[2]; };

struct Base {
    [[no_unique_address]] A a;
    char ch2;
};

struct D : Base {
    char ch3;
};

int x = sizeof(A);
int y = sizeof(Base);
int z = sizeof(D);
```

https://godbolt.org/z/Yna9b4535

Observed behavior:

z is initialized to 6.

Expected behavior:

z is initialized to 4.

Explanation:

Base is not POD for the purpose of layout as it has a potentially-overlapping
non-static data member. As a result `ch3` should be allocated on the
tail-padding of `Base` and `D` should have the same size as `Base`.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210329/1299a9f2/attachment.html>


More information about the llvm-bugs mailing list