Question

Given the following

#include <array>

struct litmus final : std::array<unsigned char, 16>
{
};

static_assert(std::is_pod<std::array<unsigned char, 16> >::value, "not pod");

// this fails on MSVC:
static_assert(std::is_pod<litmus>::value, "not pod");

The following compilers agree that litmus is pod:

However, MSVC12 (VS2013 RTM) maintains that the second assert fails.

  1. Who's right?
  2. Is there any trick to make MSVC treat the class as pod?

EDIT For information: is_trivially_copyable<litmus> returns true-ness on MSVC. This might be useful for many cases where actual POD-ness isn't strictly required.

Was it helpful?

Solution

  1. GCC and Clang; that class is POD.

  2. That depends on what exactly you mean with "make MSVC treat the class as pod." If you mean the compiler internals, then no. However, you can (in practice) specialise the trait for litmus:

    namespace std {
    
    template <>
    struct is_pod<litmus> : std::true_type
    {};
    
    }
    

    Note that going strictly by the standard, this gives undefined behaviour (thanks @R.MartinhoFernandes for pointing this out). However, as a compiler-specific workaround, I'd expect it to work. Use without any warranty.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top