[Bug c/108054] C2X auto with struct defined in statement expression

muecker at gwdg dot de gcc-bugzilla@gcc.gnu.org
Sun Dec 18 08:24:28 GMT 2022


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

--- Comment #3 from Martin Uecker <muecker at gwdg dot de> ---

It is a major usability issue for its intended use in macros if it then
sometimes breaks due to arbitrary constraints (which __auto_type does not have,
so do not seem to be essential).

Also with the new tag rules in C2X you could also write this without 'auto'
because one could redeclare the type:

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

Finally, this example also does not work:

int foo(void)
{
    auto x = ({ struct foo { int x; } a = { }; a.x; });
    // int x = ({ struct foo { int x; } a = { }; a.x; });
}

Again, regular use of ({ }) in macros would not work without problems with
'auto' and cause random problem.s

int foo(void)
{
    int x = FOO(0); // works
    auto y = FOO(0); // mit break when FOO uses ({ }) 
}


More information about the Gcc-bugs mailing list