C ++ 11 is_pod with GCC 4.6

In the relaxed definition of POD in C ++ 11, I understand that the following structure is considered 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 the ideone link showing the complete program. (Note that ideon uses GCC 4.5)

So, am I mistaken in understanding POD in C ++ 11 or does GCC 4.6 just not meet the current requirements of C ++ 11?

+6
source share
2 answers

The POD structure should be a trivial class (C ++ 11 ยง9 [class] / 10):

A POD structure is a non-unit class that is a trivial class and a standard layout class and does not have non-static data members such as non-POD struct, non-POD union (or an 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 copied.

ยง12.1 [class.ctor] / 5 defines what a trivial default constructor is. It begins:

The default constructor is trivial if not provided by the user and ...

The default constructor, Foo<T> provided to the user and is therefore non-trivial. Therefore, Foo<int> not a POD. This, however, is the standard layout.

+6
source

Default declares default constructor, makes Foo POD. i.e.

 Foo() = default; explicit Foo(T* obj) : m_data(obj) { } 

http://ideone.com/vJltmA

+2
source

All Articles