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

◇◆丶佛笑我妖孽 提交于 2019-12-05 23:29:41

问题


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.


回答1:


  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.



来源:https://stackoverflow.com/questions/20968200/msvc12-thinks-aggregate-derived-from-stdarray-is-not-pod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!