This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/65275] New: Disappearing -Wsequence-point warning


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

            Bug ID: 65275
           Summary: Disappearing -Wsequence-point warning
           Product: gcc
           Version: 4.9.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chronokitsune3233 at gmail dot com

An unusual declaration of an array with variable size does not always elicit a
warning diagnostic on Windows 7 64-bit with a mingw-w64 target
(x86_64-w64-mingw32).  My own gcc 4.9.1 and TDM-GCC 4.8.2 both exhibit the
problem.

> type foo.i
# 1 "foo.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "foo.c"
int printf (const char *, ...);
int main (void) {
  int n = 2;
  int a[(++n, 7)];
  printf ("%d %d\n", n, (int) (sizeof a / sizeof a[0]));
}

> gcc -std=c99 -Wall foo.c
foo.c: In function 'main':
foo.c:4:10: warning: operation on 'n' may be undefined [-Wsequence-point]
   int a[(++n, 7)];

Curiously, it's not the 'sizeof' division or 'n' by themselves.  A slightly
altered copy of the file has the following in the body of 'main', and there are
no warnings with the same command line:

  int n = 2;
  int a[(++n, 7)];
  printf("%d ", n);
  printf("%d\n", (int) (sizeof a / sizeof a[0]));

And I can assign the result of the 'sizeof' division to a variable as well to
make the warning disappear:

  int n = 2;
  int a[(++n, 7)];
  int len = (int) (sizeof a / sizeof a[0]);
  printf ("%d %d\n", n, len);

I've reduced the file to avoid using #include <stdio.h>, but I received the
exact same results even when using the system header instead of the 'printf'
prototype shown on the first line, so I've ruled out that possibility.

I'm not certain whether this is undefined behavior or not, but even if it is,
why does the warning disappear, depending on the code used?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]