A Trivial Question
Defaulted functions solve two problems: they are more efficient than manual implementations and they free the programmer from the burden of defining those functions manually.
C++ makes a distinction between trivial and nontrivial special member functions. This distinction isn't purely academic; a class that has one or more nontrivial special member functions isn't a POD type. This raises another question: are defaulted functions trivial?
An inline defaulted function can be trivial. To qualify as trivial, a defaulted function must be identical to the function that the compiler would implicitly declare without the =default specifier. Additionally, the defaulted function must be inline. Consider:
struct S
{
inline S()=default;
};
The defaulted constructor of
S is trivial because the compiler would have implicitly-declared a trivial constructor for
S by default:
struct S
{
//no user-declared canonical functions. Hence, S
//has implicitly-declared trivial constructor, dtor etc.
};
However, the following defaulted destructor isn't trivial:
struct S
{
inline virtual ~S()=default;
};
The defaulted destructor is inline, which is the first criterion for qualifying as trivial. However, this destructor is virtual, whereas the implicitly-declared destructor would have been non-virtual. Therefore, the defaulted destructor of
S is
not trivial.