#include <iostream>
struct A {
const int test_;
};
static_assert(std::is_pod<A>::value, "must be POD type");
int main()
{
std::cout<<"Hello World";
return 0;
}
关于Clang和GCC,std::is_pod<A>::value
为true
,而在ICC和MSVC上为false
。
如果将const int test_;
替换为int test_;
或const int* test_
,则它也可以在ICC和MSVC上通过。
标准规定如何?
std::is_trivial<A>::value
为false
,影响了std::is_pod
)- 奇怪的是std::is_trivially_copyable<A>::value
却是true
。 - Ted Lyngmostd::is_pod
自C++20也被弃用。 - François AndrieuxA
不是平凡的,因为没有默认构造函数可用。 - user7860670const int * test_
是一个非常量成员,但它所指向的东西恰好是const
的。我敢打赌int* const test_;
也会被ICC/MSVC视为非POD。 - Nate Eldredge