[cfe-dev] C++11 POD bug

Suman Kar skarpio at gmail.com
Sun Jun 3 02:43:15 PDT 2012


Your array size specifier is a non-const object making it a variable
length array. VLAs are part of C99. They are not (yet) a part of
standard C++. This thread may be of interest to you
(<http://groups.google.com/group/comp.std.c++/browse_thread/thread/2bfe25800d4961e8/9545494bbb336dfa?pli=1>).

However, you can always use a compile time constant to specify the
size of the array.

struct Pod {
 int i;
 Pod() = default;
};

int main(int argc, char **argv) {
 const int Size = 1;                // compile time constant
 struct Pod PodArray[Size];
 return 0;
}

This compiles fine.

Regards,
Suman

On Sun, Jun 3, 2012 at 4:00 AM, Kal Conley <kcconley at gmail.com> wrote:
> Hi,
>
> I have the following code:
>
> $ cat pod.cc
> struct Pod {
>  int i;
>  Pod() = default;
> };
>
> int main(int argc, char **argv) {
>  int Size = 1;
>  Pod PodArray[Size];
>  return 0;
> }
>
> I believe that "Pod" should be a POD type in c++11. But when I try to
> compile this with clang I get:
>
> $ clang++ --std=c++11 pod.cc
> pod.cc:8:15: error: variable length array of non-POD element type 'Pod'
>  Pod PodArray[Size];
>              ^
> 1 error generated.
>
> I'm using:
>
> $ clang++ --version
> clang version 3.1 (trunk 156916)
> Target: x86_64-apple-darwin11.4.0
> Thread model: posix
>
> Thanks,
> Kal
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list