[cfe-dev] POD struct

Guillaume Marcais guillaume.marcais at marcais.net
Tue Apr 10 17:37:27 PDT 2012


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.

Thank you for your time,
Guillaume.



More information about the cfe-dev mailing list