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

            Bug ID: 98994
           Summary: Empty type with [[no_unique_address]] in union with
                    constructor is not a constant expression
           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:

```
struct empty {};

union U {
        constexpr U():
                a()
        {
        }

        [[no_unique_address]] empty a;
};

constexpr U u;
```

is incorrectly rejected by gcc 11 with the error:

```
<source>:12:13: error: 'U()' is not a constant expression
   12 | constexpr U u;
      |             ^
<source>:12:13: error: 'U()' is not a constant expression because it refers to
an incompletely initialized variable
Compiler returned: 1
```

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

This code was accepted in gcc 10.2.

Reply via email to