[cfe-dev] clang bug: constant array size is recognized as variable array size
Mike Stump
mrs at apple.com
Tue May 27 12:36:22 PDT 2008
On May 23, 2008, at 3:58 AM, Eli Friedman wrote:
> On Fri, May 23, 2008 at 3:17 AM, Csaba Hruska
> <csaba.hruska at gmail.com> wrote:
>> Hi!
>> It's me again ;)
>> I've found an another bug.
>>
>> gcc accepts it, but clang thows this:
>> error: variable length array declared outside of any function
>>
>> I'v compiled it with clang svn revision 51478.
>>
>> code:
>> #define C1 100.
>> #define C2 120.
>>
>> typedef struct
>> {
>> int A [(unsigned int)(C1*C2)];
>> } s_t;
>
> gcc is wrong here;
No, it isn't:
[#2] A constant expression can be evaluated during
translation rather than runtime, and accordingly may be used
in any place that a constant may be.
[#10] An implementation may accept other forms of constant
expressions.
> "(unsigned int)(100.*120.)" isn't an integer
> constant expression (per the definition in C99 6.6), so A is in fact
> an illegal VLA per the standard. Not sure what to do here.
If one can do FP math at compile time, an error is needlessly pedantic.
More information about the cfe-dev
mailing list