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

            Bug ID: 108054
           Summary: C2X auto with structs
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: muecker at gwdg dot de
  Target Milestone: ---

GCC rejects the following code. The C2X spec does not allow declarations in the
assignment expression for auto.  But this breaks macros that define structs
inside ({ }), so this does not seem desirable in combination with ({ }). It
this is intentional, is also not clear why other non-ordinary identifiers are
still allowed. 

void foo(void)
{
  auto b = ({ struct foo { int x; } a = { }; a; });
  auto c = ({ out: 0 });
}

<source>:5:22: error: 'struct foo' defined in underspecified object initializer


I would argue that we should also extend the language and allow

void foo(void)
{
  auto a = (struct foo { int x; }){ 0 };
  typeof(a) b = a;
}

as there is not clear reason I could see to forbid this and the limitation is
surprising. (and with the new tag compatibility rules such code wiould also
become very useful);

Reply via email to