Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSVC12 thinks aggregate derived from std::array is not pod

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:

  • clang++ version 3.5 (trunk 198621) http://coliru.stacked-crooked.com/a/7add7a2fe58a7e38
  • g++ 4.8.1 http://coliru.stacked-crooked.com/a/74cfe97f06c8c128

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.

like image 282
sehe Avatar asked Jan 07 '14 09:01

sehe


1 Answers

  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.

like image 68
Angew is no longer proud of SO Avatar answered Sep 18 '22 23:09

Angew is no longer proud of SO