Under the relaxed definition of POD in C++11, it is my understanding that the following struct is considered a POD:
template <class T>
struct Foo
{
Foo()
{ }
explicit Foo(T* obj) : m_data(obj)
{ }
T* m_data;
};
However, using GCC 4.6 and compiling with the -std=c++0x
flag, if I say:
std::cout << std::boolalpha << std::is_pod<Foo<int>>::value << std::endl;
It outputs:
false
Here is an ideone link showing the full program. (Note that ideone uses GCC 4.5)
So, is my understanding of PODs in C++11 mistaken, or is GCC 4.6 simply not up-to-date in terms of C++11 compliance?
A POD struct must be a trivial class (C++11 §9[class]/10):
A POD struct is a non-union class that is both a trivial class and a standard-layout class, and has no non-static data members of type non-POD struct, non-POD union (or array of such types).
§9[class]/6 defines what a trivial class is:
A trivial class is a class that has a trivial default constructor and is trivially copyable.
§12.1[class.ctor]/5 defines what a trivial default constructor is. It begins:
A default constructor is trivial if it is not user-provided and...
The default constructor of Foo<T>
is user-provided and is therefore nontrivial. Therefore, Foo<int>
is not POD. It is, however, standard layout.
Default declaring default constructor, makes Foo a POD. i.e.
Foo() = default;
explicit Foo(T* obj) : m_data(obj)
{ }
http://ideone.com/vJltmA
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With