public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/67661] New: Wrong warning when declare VLAs: operation on 'b' may be undefined [-Wsequence-point]
@ 2015-09-21  6:19 leechung at 126 dot com
  2015-09-24  1:08 ` [Bug c/67661] Wrong warning when declare VLAs: operation on 'x' " leechung at 126 dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: leechung at 126 dot com @ 2015-09-21  6:19 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 67661
           Summary: Wrong warning when declare VLAs: operation on 'b' may
                    be undefined [-Wsequence-point]
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: leechung at 126 dot com
  Target Milestone: ---

The following code produces a warning: operation on 'b' may be
undefined.[-Wsequence-point]

int x = 0, y [++ x], z [++ x];

But N1570 6.8 says:
A block allows a set of declarations and statements to be grouped into one
syntactic unit. The initializers of objects that have automatic storage
duration, and the variable length array declarators of ordinary identifiers
with block scope, are evaluated and the values are stored in the objects
(including storing an indeterminate value in objects without an initializer)
each time the declaration is reached in the order of execution, as if it were a
statement, and within each declaration in the order that declarators appear.

and 6.7.6 says:
A full declarator is a declarator that is not part of another declarator. The
end of a full declarator is a sequence point.


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

* [Bug c/67661] Wrong warning when declare VLAs: operation on 'x' may be undefined [-Wsequence-point]
  2015-09-21  6:19 [Bug c/67661] New: Wrong warning when declare VLAs: operation on 'b' may be undefined [-Wsequence-point] leechung at 126 dot com
@ 2015-09-24  1:08 ` leechung at 126 dot com
  2015-09-24  7:06 ` manu at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: leechung at 126 dot com @ 2015-09-24  1:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from leechung <leechung at 126 dot com> ---
(In reply to joseph@codesourcery.com from comment #1)
> You'll need to give a full testcase (complete compilable file and options 
> used to compile it).  What you gave isn't a compilable testcase; it gives 
> "error: variably modified 'y' at file scope".  Put inside a function, it 
> gives "warning: unused variable 'y' [-Wunused-variable]", but does not 
> give the warning you mention.  And there's no variable 'b' in your example 
> at all.

Sorry, I am less experience.
The following is the complete code:

#include <stdio.h>

int main (void)
{
    int x = 0, y [++ x], z [++ x];
    printf ("%d, %d, %d\n", sizeof x, sizeof y, sizeof z);
    return 0;
}

and are compiled with option '-Wall'.for example:
gcc xx.c -Wall

then produce a warning 'operation on 'x' may be undefined [-Wsequence-point]'


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

* [Bug c/67661] Wrong warning when declare VLAs: operation on 'x' may be undefined [-Wsequence-point]
  2015-09-21  6:19 [Bug c/67661] New: Wrong warning when declare VLAs: operation on 'b' may be undefined [-Wsequence-point] leechung at 126 dot com
  2015-09-24  1:08 ` [Bug c/67661] Wrong warning when declare VLAs: operation on 'x' " leechung at 126 dot com
@ 2015-09-24  7:06 ` manu at gcc dot gnu.org
  2015-09-24  8:14 ` frankhb1989 at gmail dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu.org @ 2015-09-24  7:06 UTC (permalink / raw)
  To: gcc-bugs

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

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu.org

--- Comment #3 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
int main (void)
{
    int x = 0, y [++ x], z [++ x];
    __builtin_printf ("%d, %d, %d\n", sizeof x, sizeof y, sizeof z);
    return 0;
}

$ cc1 -Wsequence-point test.c
test.c:3:27: warning: operation on ‘x’ may be undefined [-Wsequence-point]
   int x = 0, y [++ x], z [++ x];
                           ^

I'll let someone else with more knowledge of the standard to decide if the
warning is correct or not.
>From gcc-bugs-return-497946-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Sep 24 07:25:11 2015
Return-Path: <gcc-bugs-return-497946-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 34658 invoked by alias); 24 Sep 2015 07:25:11 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 34598 invoked by uid 48); 24 Sep 2015 07:25:07 -0000
From: "mpolacek at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/67661] Wrong warning when declare VLAs: operation on 'x' may be undefined [-Wsequence-point]
Date: Thu, 24 Sep 2015 07:25:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c
X-Bugzilla-Version: 5.2.0
X-Bugzilla-Keywords: diagnostic
X-Bugzilla-Severity: normal
X-Bugzilla-Who: mpolacek at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: cc
Message-ID: <bug-67661-4-oOKeuKpGb4@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-67661-4@http.gcc.gnu.org/bugzilla/>
References: <bug-67661-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-09/txt/msg01924.txt.bz2
Content-length: 440

https://gcc.gnu.org/bugzilla/show_bug.cgi?idg661

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I think the warning is bogus and the code looks valid.


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

* [Bug c/67661] Wrong warning when declare VLAs: operation on 'x' may be undefined [-Wsequence-point]
  2015-09-21  6:19 [Bug c/67661] New: Wrong warning when declare VLAs: operation on 'b' may be undefined [-Wsequence-point] leechung at 126 dot com
  2015-09-24  1:08 ` [Bug c/67661] Wrong warning when declare VLAs: operation on 'x' " leechung at 126 dot com
  2015-09-24  7:06 ` manu at gcc dot gnu.org
@ 2015-09-24  8:14 ` frankhb1989 at gmail dot com
  2015-09-24 16:23 ` joseph at codesourcery dot com
  2015-09-24 16:25 ` mpolacek at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: frankhb1989 at gmail dot com @ 2015-09-24  8:14 UTC (permalink / raw)
  To: gcc-bugs

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

frankhb1989 at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |frankhb1989 at gmail dot com

--- Comment #5 from frankhb1989 at gmail dot com ---
"%d" in the case should be replaced by "%zu".
Confirmed that clang 3.7 does not complain about it.


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

* [Bug c/67661] Wrong warning when declare VLAs: operation on 'x' may be undefined [-Wsequence-point]
  2015-09-21  6:19 [Bug c/67661] New: Wrong warning when declare VLAs: operation on 'b' may be undefined [-Wsequence-point] leechung at 126 dot com
                   ` (2 preceding siblings ...)
  2015-09-24  8:14 ` frankhb1989 at gmail dot com
@ 2015-09-24 16:23 ` joseph at codesourcery dot com
  2015-09-24 16:25 ` mpolacek at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: joseph at codesourcery dot com @ 2015-09-24 16:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
The warning is bogus.  It appears even if separate declarations are used 
for the three variables; maybe it's something to do with the printf call?


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

* [Bug c/67661] Wrong warning when declare VLAs: operation on 'x' may be undefined [-Wsequence-point]
  2015-09-21  6:19 [Bug c/67661] New: Wrong warning when declare VLAs: operation on 'b' may be undefined [-Wsequence-point] leechung at 126 dot com
                   ` (3 preceding siblings ...)
  2015-09-24 16:23 ` joseph at codesourcery dot com
@ 2015-09-24 16:25 ` mpolacek at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-09-24 16:25 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-09-24
     Ever confirmed|0                           |1


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

end of thread, other threads:[~2015-09-24 16:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-21  6:19 [Bug c/67661] New: Wrong warning when declare VLAs: operation on 'b' may be undefined [-Wsequence-point] leechung at 126 dot com
2015-09-24  1:08 ` [Bug c/67661] Wrong warning when declare VLAs: operation on 'x' " leechung at 126 dot com
2015-09-24  7:06 ` manu at gcc dot gnu.org
2015-09-24  8:14 ` frankhb1989 at gmail dot com
2015-09-24 16:23 ` joseph at codesourcery dot com
2015-09-24 16:25 ` mpolacek at gcc dot gnu.org

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).