[cfe-dev] Does your cfe consider this code in error?

Eli Friedman eli.friedman at gmail.com
Sun Jun 1 15:25:58 PDT 2008


On Sun, Jun 1, 2008 at 2:54 PM, Steve Naroff <snaroff at apple.com> wrote:
> I just noticed that GCC does complain if the "char *" is the topmost
> cast.
>
> [steve-naroffs-imac:llvm/tools/clang] snaroff% ../../Debug/bin/clang
> ary.c
> ary.c:3:16: error: size of array has non-integer type 'char *'
>   char control[(char *)2];
>                ^~~~~~~~~

This isn't legal simply because the size of an array must have an
integer type.  This doesn't say anything useful.

>> struct {
>>   char control[((int)(char *)2)];
>> } xx;

"Cast operators in an integer constant expression shall only convert
arithmetic types to integer types", so (int)(char*)2 is not an ICE.
Therefore, the declarator declares a variable length array, and since
struct members aren't allowed to have a variably modified type, this
is illegal.

This was already discussed recently; see
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2008-May/001771.html.

-Eli



More information about the cfe-dev mailing list