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

            Bug ID: 119661
           Summary: Possible "accepts invalid": member access into
                    incomplete type 'struct s'
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pavel.morozkin at gmail dot com
  Target Milestone: ---

Note: this may be a duplicate.

This C++ code:
struct s
{
    int x;
    int y[sizeof((struct s*)0)->x];
};

compiled with g++ -std=c++26 -pedantic -Wall -Wextra produces:
<nothing>

while compiled with clang -std=c++26 -pedantic -Wall -Wextra produces:
<source>:4:31: error: member access into incomplete type 'struct s'
    4 |     int y[sizeof((struct s*)0)->x];
      |                               ^
<source>:1:8: note: definition of 's' is not complete until the closing '}'
    1 | struct s
      |        ^

Online demo: https://gcc.godbolt.org/z/nvrrM7zez.

Who is correct? (Please elaborate by quoting the C++ standard.)

Originates from: https://stackoverflow.com/q/79538353/1778275.

Reply via email to