[cfe-dev] POD struct

Eli Friedman eli.friedman at gmail.com
Tue Apr 10 18:04:42 PDT 2012


On Tue, Apr 10, 2012 at 5:37 PM, Guillaume Marcais
<guillaume.marcais at marcais.net> wrote:
> The following simple program creates a variable length array of structures:
>
> //template<typename T>
> class Test {
> public:
>  struct toto {
>    int* x;
>  };
>
>  void method(int nb) {
>    toto ary[nb];
>    for(int i = 0; i < nb; ++i)
>      ary[i].x = 0;
>  }
> };
>
>
> int main(int argc, char* argv[]) {
>  //Test<char> t;
>  Test t;
>  t.method(5);
>
>  return 0;
> }
>
> In compiles properly as written with clang++ (version 3.0). When
> uncommeting the templated version, then the compiler complains:
>
> POD.cc:9:13: error: variable length array of non-POD element type
> 'Test<char>::toto'
>    toto ary[nb];
>
> It does not seem right. 'struct toto' still looks like a POD. Why
> isn't it one anymore?
>
> As a side note, g++ compiles this code without complaining.

Looks like a bug; please file at llvm.org/bugs/ .

-Eli




More information about the cfe-dev mailing list