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

            Bug ID: 105452
           Summary: static_assert inside nameless nested union: invalid
                    "inaccessible within this context" error
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: foobarandfoo at gmail dot com
  Target Milestone: ---

template <typename T>
struct C {
  union {
    char v;
    static_assert(sizeof(v) == sizeof(char), "");
  };
};

int main() {
    C<int> x;
}

Fails to compile in every version I tried (including 13.0, 11.3.0, 11.2.0,
11.1.0, 10.3, 9.4) with "error: ‘char C<int>::<unnamed struct>::v’ is
inaccessible within this context static_assert(sizeof(v) == sizeof(char),
"");". If we modify struct C to be non-templated, the code compiles
successfully. Clang and MSVC compile the initial code.

https://godbolt.org/z/j171x1aGz

Reply via email to