[cfe-dev] Variable length arrays are not permitted in C++

Douglas Gregor dgregor at apple.com
Tue Feb 16 10:46:19 PST 2010


On Feb 16, 2010, at 9:08 AM, Eli Friedman wrote:

> On Tue, Feb 16, 2010 at 7:52 AM, Rene Rebe <rene at exactcode.de> wrote:
>> Hi,
>> 
>> On 16.02.2010, at 16:39, Eli Friedman wrote:
>> 
>>> On Tue, Feb 16, 2010 at 3:21 AM, Rene Rebe <rene at exactcode.de> wrote:
>>>> Hi all,
>>>> 
>>>> starting to play with Clang++ I notices this (building our Open Source ExactImage), currently on x86_64, T2 Linux:
>>>> 
>>>> lib/Colorspace.cc:442:22: error: variable length arrays are not permitted in C++
>>>>  uint8_t gray_lookup[vmax];
>>> 
>>> VLAs are disabled until someone goes through and makes sure they work
>>> properly and that we give appropriate errors for C++-only constructs.
>> 
>> 
>> Well, what's needed? I'm certainly interested in LLVM and getting further into it. Though I'm not yet too familiar with the codebase, yet, nor am an language lawyer.
>> 
>> Basic, POD, use appear to just work after I enabled it with the patch posted before. Any pointers welcome.
> 
> Anything that works in C probably works in C++ as well; it gets
> complicated when we try to deal with constructs like VLAs with
> non-trivial destructors, using a VLA with new, attempting to use a
> variably modified type as a template argument, attempting to use a
> variably modified type inside a local class, etc.  The idea is that if
> we're going to support VLAs inside of C++, we should make sure they
> work correctly in every situation, not just in trivial cases.


I would be perfectly happy to have Clang produce errors for all of these cases, so that VLAs in C++ are restricted to the places where they work in C. A patch that correctly restricts VLAs to that subset, and downgrades the "variable length arrays are not permitted in C++" error to an ExtWarn, will be accepted.

	- Doug



More information about the cfe-dev mailing list