Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7953 Discussions

C compiler: missing diagnostics "expression is not an integer constant expression"

pmor
Beginner
1,833 Views

Sample code:

enum { x = (int)(0.0 + 0.0) };

Invocation: icl -std=c11 -Wall -Wextra -pedantic

Expected diagnostics: warning: expression is not an integer constant expression

Actual diagnostics: <nothing>

Version: icc 2021.1.2 on x86-64 on Linux

C11, 6.6 Constant expressions, 6:
> An integer constant expression 117) shall have integer type and shall only have operands
that are integer constants, enumeration constants, character constants, sizeof
expressions whose results are integer constants, _Alignof expressions, and floating
constants that are the immediate operands of casts. Cast operators in an integer constant
expression shall only convert arithmetic types to integer types, except as part of an
operand to the sizeof or _Alignof operator.

Also: it seems that this diagnostic is required under -strict-ansi as well.

0 Kudos
8 Replies
DitiD_Intel
Moderator
1,797 Views

Hi,


Thank you for posting in Intel Communities.


We are also able to reproduce your issue at our end.

We are working on this internally and we'll get back to you soon.

Meanwhile, could you please try with icx compiler?


Thanks and Regards,

Ditipriya.


0 Kudos
Viet_H_Intel
Moderator
1,779 Views

Looks like Intel compiler misses a warning on this case. I'll see if there is another option to catch this issue.

Not sure if you are aware of, but C++ Classic compiler will be enter "Legacy Product Support" mode signaling the end of regular updates. Please see https://www.intel.com/content/www/us/en/developer/articles/technical/adoption-of-llvm-complete-icx.html


Thanks,


0 Kudos
Viet_H_Intel
Moderator
1,771 Views

I don't think we have a way to get a diagnostic on this from Classic C++ Compiler.

Is this an important diagnostic that you would like Classic C++ Compiler to be able to emit?


Thanks,


0 Kudos
pmor
Beginner
1,758 Views

@Viet_H_Intel As I understand, "icx compiler" is a C++ compiler. From the "Invocation" we see that the language is C, not C++. The 6.6 Constant expressions, 6 is in Semantics section, not Constraints, so no diagnostic is required, but as a quality-of-implementation matter Intel C compiler should diagnose it.

0 Kudos
Viet_H_Intel
Moderator
1,754 Views

On Linux icx is a driver for C code whereas icpx is a driver to C++ code.

And on Windows icx is a driver for both C and C++. Looks like icx on Windows isn't emit this warning.


Thanks,



0 Kudos
Viet_H_Intel
Moderator
1,718 Views

I didn't use a corrected flag on my last post regarding icx on Windows.

icx actually emits a warning:

 

> icx t.c -c -Wpedantic

Intel(R) oneAPI DPC++/C++ Compiler for applications running on Intel(R) 64, Version 2022.0.0 Build 20211123

Copyright (C) 1985-2021 Intel Corporation. All rights reserved.

 

t.c(1,12): warning: expression is not an integer constant expression; folding it to a constant is a GNU extension [-Wgnu-folding-constant]

enum { x = (int)(0.0 + 0.0) };

      ^~~~~~~~~~~~~~~~

1 warning generated.

 

0 Kudos
Viet_H_Intel
Moderator
1,711 Views

Hi,

I've reported this issue to our Front End team.

Thanks,


0 Kudos
Devorah_H_Intel
Moderator
1,451 Views

The fix is in the upcoming oneAPI 2022.3 release. 

0 Kudos
Reply