[basic.def.odr]/3 引用了术语“非平凡函数”,我在标准 (N4140) 中找不到它的定义。
[basic.def.odr]/3
A variable x whose name appears as a potentially-evaluated expression ex is odr-used by ex unless applying the lvalue-to-rvalue conversion (4.1) to x yields a constant expression (5.19) that does not invoke any nontrivial functions and, if x is an object, ex is an element of the set of potential results of an expression e, where either the lvalue-to-rvalue conversion (4.1) is applied to e, or e is a discarded-value expression (Clause 5).
最佳答案
“非平凡函数”是“平凡特殊成员函数”的补充。对于平凡和不平凡的默认/复制/移动构造函数、复制/移动赋值运算符或析构函数有什么定义 - 仅属于特殊成员函数的特征,并决定是否这些需要在某些情况下调用。
这些的定义可以在第 12 章中找到。
默认构造函数,§12.1/4:
A default constructor is trivial if it is not user-provided and if:
- its class has no virtual functions (10.3) and no virtual base classes (10.1), and
- no non-static data member of its class has a brace-or-equal-initializer, and
- all the direct base classes of its class have trivial default constructors, and
- for all the non-static data members of its class that are of class type (or array thereof), each such class has a trivial default constructor.
Otherwise, the default constructor is non-trivial.
复制/移动构造函数,第 12.8/12 节:
A copy/move constructor for class X is trivial if it is not user-provided, its parameter-type-list is equivalent to the parameter-type-list of an implicit declaration, and if
- class
X
has no virtual functions (10.3) and no virtual base classes (10.1), and- class
X
has no non-static data members of volatile-qualified type, and- the constructor selected to copy/move each direct base class subobject is trivial, and
- for each non-static data member of
X
that is of class type (or array thereof), the constructor selected to copy/move that member is trivial;otherwise the copy/move constructor is non-trivial.
复制/移动赋值运算符,§12.8/26:
A copy/move assignment operator for class
X
is trivial if it is not user-provided, its parameter-type-list is equivalent to the parameter-type-list of an implicit declaration, and if
- class
X
has no virtual functions (10.3) and no virtual base classes (10.1), and- class
X
has no non-static data members of volatile-qualified type, and- the assignment operator selected to copy/move each direct base class
- for each non-static data member of
X
that is of class type (or array thereof), the assignment operator selected to copy/move that member is trivial;otherwise the copy/move assignment operator is non-trivial.
析构函数,§12.4/5:
A destructor is trivial if it is not user-provided and if:
- the destructor is not virtual,
- all of the direct base classes of its class have trivial destructors, and
- for all of the non-static data members of its class that are of class type (or array thereof), each such class has a trivial destructor.
Otherwise, the destructor is non-trivial
关于c++ - 什么是微不足道的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30152687/