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

            Bug ID: 92399
           Summary: Rejects valid: reading of an inactive union member
                    that shares common initial sequence with the active on
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nok.raven at gmail dot com
  Target Milestone: ---

The wording is in [class.union]/1 and [class.mem]/25.

[class.mem]/25 contains an example:

struct T1 { int a, b; };
struct T2 { int c; double d; };
union U { T1 t1; T2 t2; };
int f() {
  U u = { { 1, 2 } };   // active member is t1
  return u.t2.c;        // OK, as if u.t1.a were nominated
}

Running this example in constexpr context produces an error:
<source>:8:20:   in 'constexpr' expansion of 'f()'
<source>:8:21: error: accessing 'U::t2' member instead of initialized 'U::t1'
member in constant expression
    8 | constexpr int i = f();
      |                     ^
Compiler returned: 1

https://godbolt.org/z/ZNK716

Reply via email to