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: potrepa...@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.

Reply via email to