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

            Bug ID: 98995
           Summary: Copy elision not applied to members declared with
                    [[no_unique_address]]
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: david at doublewise dot net
  Target Milestone: ---

The following valid translation unit is rejected by gcc 11:

```
struct non_movable {
        non_movable() = default;
        non_movable(non_movable &&) = delete;
};

struct wrapper {
        constexpr explicit wrapper(auto function):
                m(function())
        {
        }

        [[no_unique_address]] non_movable m;
};

constexpr auto w = wrapper{[]{ return non_movable(); }};
```

with the error message

```
<source>: In instantiation of 'constexpr wrapper::wrapper(auto:1) [with auto:1
= <lambda()>]':
<source>:15:55:   required from here
<source>:8:17: error: use of deleted function
'non_movable::non_movable(non_movable&&)'
    8 |                 m(function())
      |                 ^~~~~~~~~~~~~
<source>:3:9: note: declared here
    3 |         non_movable(non_movable &&) = delete;
      |         ^~~~~~~~~~~
Compiler returned: 1
```

See it live: https://godbolt.org/z/o1TbY9

This was accepted in gcc 10.2.

Reply via email to