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

            Bug ID: 116313
           Summary: -Wsequence-point false positive with auto and/or
                    __auto_type
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alx at kernel dot org
  Target Milestone: ---

Originally found in
<https://software.codidact.com/comments/thread/9880#comment-24855>.
Originally reported in
<https://inbox.sourceware.org/gcc/577174b2608dc8e4ff7dd5f7ad57406ffe46da54.ca...@gwdg.de/T/>.


$ cat auto.c
#include <stdio.h>

int
main(void)
{
        int  i = 3;
        int  a[2 * i];
        int  (*p)[2 * i];

        i = 1;
        p = &a;
        auto q = p + i++;
}
$ gcc -Wsequence-point -std=c23 auto.c
auto.c: In function ‘main’:
auto.c:12:23: warning: operation on ‘i’ may be undefined [-Wsequence-point]
   12 |         auto q = p + i++;
      |                      ~^~


I suspect the warning is confusing auto with typeof().  If typeof()
was used, this would indeed cause double evaluation, once before the =
and once after the =, causing UB.

Maybe it's due to how auto is implemented?  I suspect it's doing
internally:

        typeof(p + i++) q = p + i++;

and that would be problematic.  I can reproduce it with both gcc-13 and
gcc-14.

Reply via email to