public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/60838] New: bugos warning: initializer element is not a constant expression: int test = (0 ? (1,0) : 0) + 1;
@ 2014-04-14  5:40 potrepalov@asc-ural.ru
  2014-04-14  6:41 ` [Bug c/60838] " potrepalov@asc-ural.ru
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: potrepalov@asc-ural.ru @ 2014-04-14  5:40 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60838

            Bug ID: 60838
           Summary: bugos warning: initializer element is not a constant
                    expression: int test = (0 ? (1,0) : 0) + 1;
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: potrepalov@asc-ural.ru

main.c:
-------------
int test = (0 ? (3, 0) : 0) + 1;
int main( void ) { return 0; }
-------------

>gcc main.c
main.c:1:12: warning: initializer element is not a constant expression


This is work, but generate warning:

#define CT_ASSERT_EXPR(ex)  (0 ? ((struct { int a:((ex) ? 1 : -1); } *)0,0) :
0)
#define CT_ASSERT(ex)       extern char ct_assert_[ CT_ASSERT_EXPR(ex)+1 ]

warning: variably modified 'ct_assert_' at file scope


According C standart:

6.6 Constant expressions

Constant expressions shall not contain assignment, increment, decrement,
function-call, or comma operators, except when they are contained within a
subexpression that is not evaluated.


6.5.15 Conditional operator

The first operand is evaluated; there is a sequence point after its evaluation.
The second operand is evaluated only if the first compares unequal to 0; the
third operand is evaluated only if the first compares equal to 0; the result is
the value of the second or third operand (whichever is evaluated), converted to
the type described below.


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

* [Bug c/60838] bugos warning: initializer element is not a constant expression: int test = (0 ? (1,0) : 0) + 1;
  2014-04-14  5:40 [Bug c/60838] New: bugos warning: initializer element is not a constant expression: int test = (0 ? (1,0) : 0) + 1; potrepalov@asc-ural.ru
@ 2014-04-14  6:41 ` potrepalov@asc-ural.ru
  2014-04-15  8:00 ` mpolacek at gcc dot gnu.org
  2014-04-15  8:17 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: potrepalov@asc-ural.ru @ 2014-04-14  6:41 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60838

--- Comment #1 from ilya <potrepalov@asc-ural.ru> ---
Another testcase:

main.c
-----------------
int test1 = (0 ? 0 : 0) + 1;
int test2 = (0 ? (3, 0) : 0) + 1;
int test3[(0 ? 0 : 0) + 1];
int test4[(0 ? (3, 0) : 0) + 1];

int main( void ) { return 0; }
-----------------

>gcc main.c
main.c:2:13: warning: initializer element is not a constant expression
main.c:4:5: error: variably modified ‘test4’ at file scope


Checked for:
gcc version 4.5.3 (GCC) 
gcc version 4.7.3
>From gcc-bugs-return-448942-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Apr 14 07:32:36 2014
Return-Path: <gcc-bugs-return-448942-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 9440 invoked by alias); 14 Apr 2014 07:32:35 -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 9407 invoked by uid 48); 14 Apr 2014 07:32:31 -0000
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/60836] [4.7/4.8/4.9/4.10 Regression] invalid PHI argument and ICE in verify_gimple
Date: Mon, 14 Apr 2014 07:32: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: unknown
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: jakub at gcc dot gnu.org
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 4.7.4
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status cf_reconfirmed_on cc target_milestone short_desc everconfirmed
Message-ID: <bug-60836-4-JFpOglMvfF@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-60836-4@http.gcc.gnu.org/bugzilla/>
References: <bug-60836-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: 2014-04/txt/msg00962.txt.bz2
Content-length: 888

http://gcc.gnu.org/bugzilla/show_bug.cgi?id`836

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-04-14
                 CC|                            |jakub at gcc dot gnu.org
   Target Milestone|---                         |4.7.4
            Summary|[4.9 Regression] invalid    |[4.7/4.8/4.9/4.10
                   |PHI argument and ICE in     |Regression] invalid PHI
                   |verify_gimple               |argument and ICE in
                   |                            |verify_gimple
     Ever confirmed|0                           |1

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Started with r173856.


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

* [Bug c/60838] bugos warning: initializer element is not a constant expression: int test = (0 ? (1,0) : 0) + 1;
  2014-04-14  5:40 [Bug c/60838] New: bugos warning: initializer element is not a constant expression: int test = (0 ? (1,0) : 0) + 1; potrepalov@asc-ural.ru
  2014-04-14  6:41 ` [Bug c/60838] " potrepalov@asc-ural.ru
@ 2014-04-15  8:00 ` mpolacek at gcc dot gnu.org
  2014-04-15  8:17 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-04-15  8:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60838

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

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

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I actually don't think this is a bug.  While C99/C11 say what you wrote about
Constant expressions, C89 says something else:
"Constant expressions shall not contain assignment, increment, decrement,
function-call, or comma operators, except when they are contained within the
operand of a sizeof operator."
And really:
int u = sizeof ((0 ? (3, 0) : 0) + 1);
issues no warnings even with -std=c89.  The default is still -std=gnu89, so you
may want to use e.g. -std=gnu99.


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

* [Bug c/60838] bugos warning: initializer element is not a constant expression: int test = (0 ? (1,0) : 0) + 1;
  2014-04-14  5:40 [Bug c/60838] New: bugos warning: initializer element is not a constant expression: int test = (0 ? (1,0) : 0) + 1; potrepalov@asc-ural.ru
  2014-04-14  6:41 ` [Bug c/60838] " potrepalov@asc-ural.ru
  2014-04-15  8:00 ` mpolacek at gcc dot gnu.org
@ 2014-04-15  8:17 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-04-15  8:17 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60838

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |jakub at gcc dot gnu.org
         Resolution|---                         |INVALID

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Yeah, with e.g. -std=c89 -pedantic-errors you get the desired diagnostics on
#c1 test, while with -std=c99 -pedantic-errors it is accepted.


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

end of thread, other threads:[~2014-04-15  8:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-14  5:40 [Bug c/60838] New: bugos warning: initializer element is not a constant expression: int test = (0 ? (1,0) : 0) + 1; potrepalov@asc-ural.ru
2014-04-14  6:41 ` [Bug c/60838] " potrepalov@asc-ural.ru
2014-04-15  8:00 ` mpolacek at gcc dot gnu.org
2014-04-15  8:17 ` jakub 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).