7

The following code

#include <iostream>
#include <new>
#include <cstring>
#include <type_traits>

template<typename T>
void is_pod(char* c)
{
    cout << "Type " << c;
    if(std::is_pod<T>::value)
        ::std::cout << " is POD" << endl;
    else
        ::std::cout << " is not!" << endl;
}

#define CHECK_TYPE(ty) ::is_pod<ty>(#ty)

struct POD_Parent{};
struct POD_Child : public POD_Parent{int y;};
struct POD_Child2 {int x; POD_Parent y; POD_Child ssd;};

int main()
{
    CHECK_TYPE(POD_Parent);
    CHECK_TYPE(POD_Child);
    CHECK_TYPE(POD_Child2);

Gives the following results: Which is strange!

Type POD_Parent is POD
Type POD_Child is not!
Type POD_Child2 is POD

How can POD_Child is not POD?! and POD_Child2 is POD?!!

Note that I compiled it using MinGW (using option -std=c++11) and it said that all of them are POD.

Jonas
  • 121,568
  • 97
  • 310
  • 388
Yousf
  • 3,957
  • 3
  • 27
  • 37
  • sorry i didn't see POD_Child as a member of POD_Child2, i deleted the answer as it was not correct :) – Hayri Uğur Koltuk Feb 19 '13 at 16:39
  • 1
    [Things have changed (quite a bit) since 2008](http://stackoverflow.com/questions/4178175/what-are-aggregates-and-pods-and-how-why-are-they-special/7189821#7189821), and the old compiler has probably just got it wrong. – Bo Persson Feb 19 '13 at 16:47
  • I get the same result in VC2010 as you got in 2008. – user93353 Feb 19 '13 at 16:54
  • VC2012 the same result. It is a bug, obviously. So, please, file it to MS connect – ixSci Feb 19 '13 at 17:09
  • 1
    It must be a bug in MSVC. More on POD types: http://stackoverflow.com/questions/146452/what-are-pod-types-in-c – kispaljr Feb 26 '13 at 09:34

1 Answers1

0

According to [MSDN][1] a type that has a base class is not POD so POD_Child is not POD but for POD_Child2 its possibly some mistake of the compiler that ignore base class of ssd

BigBoss
  • 6,904
  • 2
  • 23
  • 38