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

Rene Rebe rene at exactcode.de
Tue Feb 16 03:48:40 PST 2010


Hello again,

On 16.02.2010, at 12:21, Rene Rebe 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];
> 
> the code is straight forward variable length array, like:
> 
> ..
>  const int vmax = 1 << bps;
>  uint8_t gray_lookup[vmax];
> 
> The error already indicates it is intentionally disabled in clang++ for C++
> 
> Even old (3.x?) versions of G++ happily accept this.
> 
> Is there an std=c99 like option to allow this in Clang++? Maybe it should accept it by default and warn that it is not portable, GNU extension (but I think present in C++0x)?
> 
> René
> 


This trivial changes makes some quick test work:

--- tools/clang/lib/Sema/SemaType.cpp	(revision 96337)
+++ tools/clang/lib/Sema/SemaType.cpp	(working copy)
@@ -686,7 +686,7 @@
     T = Context.getConstantArrayType(T, ConstVal, ASM, Quals);
   }
   // If this is not C99, extwarn about VLA's and C99 array size modifiers.
-  if (!getLangOptions().C99) {
+  if (!getLangOptions().C99 && !getLangOptions().CPlusPlus) {
     if (ArraySize && !ArraySize->isTypeDependent() &&
         !ArraySize->isValueDependent() &&
         !ArraySize->isIntegerConstantExpr(Context))

I'm aware that this is not apply-worthy code, ...

-- 
  René Rebe, ExactCODE GmbH, Jaegerstr. 67, DE-10117 Berlin
  http://exactcode.com | http://t2-project.org | http://rene.rebe.name





More information about the cfe-dev mailing list