#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;
}
On Clang and GCC std::is_pod<A>::value
is true
, while on ICC and MSVC it is false
.
If const int test_;
is replaced with either int test_;
or const int* test_
then it also passes on ICC and MSVC.
What does the standard say?
A POD (plain old data) object has one of these data types--a fundamental type, pointer, union, struct, array, or class--with no constructor. Conversely, a non-POD object is one for which a constructor exists.
The struct MyStruct has no user-defined ctor, dtor, etc and hence is a POD.
POD's and trivial classes are now allowed to have constructors, as long as trivial default constructor, copy constructor, copy assignment, and destructor are available. POD's and standard-layout types are now allowed to have access control. All non-static data members must have the same access control.
In computer science and object-oriented programming, a passive data structure (PDS, also termed a plain old data structure, or plain old data, POD) is a term for a record, to contrast with objects.
N4659
12/10
A POD struct is a non-union class that is both a trivial class and a standard-layout class, and has no non-static data members of type non-POD struct, non-POD union (or array of such types).
For trivial
12/6
A trivial class is a class that is trivially copyable and has one or more default constructors
There is no available default constructor.
Further, for trivially copyable, the requirements include
12/6.2
that has at least one non-deleted copy constructor, move constructor, copy assignment operator, or move assignment operator
Since you include a const int
, it's not trivially copyable (no assignment operators), so it is not a pod
^ I was wrong, it is copyable by having the constructors. I misread the "or" as "and"
One of the requirements for POD type is to be a trivial type.
[class]
10 A POD struct 109 is a non-union class that is both a trivial class and a standard-layout class, and has no non-static data members of type non-POD struct, non-POD union (or array of such types). where trivial type
while trivial is defined in the same section as
6 A trivial class is a class that is trivially copyable and has one or more default constructors (15.1), all of which are either trivial or deleted and at least one of which is not deleted.
Since A
has a field with const-qualifier which requires mandatory initialization, its implicitly declared default constructor is deleted. Therefore A
is not trivial type and not a POD type. So VS and ICC are correct here. But it is probably not a big deal since POD trait became deprecated in C++20 and should be avoided in code using preceding standards.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With