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

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