public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/65275] New: Disappearing -Wsequence-point warning
@ 2015-03-02 11:29 chronokitsune3233 at gmail dot com
  2015-03-02 12:20 ` [Bug c/65275] " glisse at gcc dot gnu.org
  2015-03-04 16:48 ` joseph at codesourcery dot com
  0 siblings, 2 replies; 3+ messages in thread
From: chronokitsune3233 at gmail dot com @ 2015-03-02 11:29 UTC (permalink / raw)
  To: gcc-bugs

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?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/65275] Disappearing -Wsequence-point warning
  2015-03-02 11:29 [Bug c/65275] New: Disappearing -Wsequence-point warning chronokitsune3233 at gmail dot com
@ 2015-03-02 12:20 ` glisse at gcc dot gnu.org
  2015-03-04 16:48 ` joseph at codesourcery dot com
  1 sibling, 0 replies; 3+ messages in thread
From: glisse at gcc dot gnu.org @ 2015-03-02 12:20 UTC (permalink / raw)
  To: gcc-bugs

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

Marc Glisse <glisse at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-03-02
     Ever confirmed|0                           |1

--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
Something to do with save_expr I guess (it also explains why the warning is on
the wrong line).


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/65275] Disappearing -Wsequence-point warning
  2015-03-02 11:29 [Bug c/65275] New: Disappearing -Wsequence-point warning chronokitsune3233 at gmail dot com
  2015-03-02 12:20 ` [Bug c/65275] " glisse at gcc dot gnu.org
@ 2015-03-04 16:48 ` joseph at codesourcery dot com
  1 sibling, 0 replies; 3+ messages in thread
From: joseph at codesourcery dot com @ 2015-03-04 16:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
The warning here appears to be bogus; the code looks well-defined to me.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-03-04 16:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-02 11:29 [Bug c/65275] New: Disappearing -Wsequence-point warning chronokitsune3233 at gmail dot com
2015-03-02 12:20 ` [Bug c/65275] " glisse at gcc dot gnu.org
2015-03-04 16:48 ` joseph at codesourcery dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).