The*_*Zoo 6 c++ type-traits language-lawyer template-meta-programming
以下摘录使用Clang-libstdc ++或Clang-libc ++,GCC,它们的许多版本以及该语言自11(14&17)以来的所有三个版本进行编译:
#include <type_traits>
struct HasUserDefinedDestructor {
~HasUserDefinedDestructor() {}
};
using HUDD = HasUserDefinedDestructor;
static_assert(not std::is_trivially_move_constructible<HUDD>::value, "");
static_assert(not std::is_trivially_copy_constructible<HUDD>::value, "");
Run Code Online (Sandbox Code Playgroud)
这使我感到惊讶,因为复制仅需要微不足道的操作。
这是编译器/库中的错误吗,还是标准在某处说明使用用户定义的析构函数会使复制和移动构造函数变得微不足道?
Edit: Why this is not a repeat of default construction question: Given the comments we know "noexceptness" and triviality of constructors are affected by the noexceptness and triviality of the destructor, but before knowing that all of these traits are related the questions are different. Having this question allows anybody to see this is related
is_trivially_constructible定义如下(粗体是我的):
\n\n\n
is_\xc2\xadconstructible_\xc2\xadv<T,Args...>是true并且 的变量定义is_\xc2\xadconstructible(如下定义)已知不会调用任何不平凡的操作
\xc2\xab 下面定义的\xc2\xbb 是[meta.unary.op]/8:
\n\n\n\n
is_\xc2\xadconstructible<T, Args...>当且仅当以下变量定义对于某些发明变量来说格式良好时,才应满足模板特化的谓词条件t:\n
T t(declval<Args>()...);
所以是的,is_trivially_[copy|move]_constructible_v当false析构函数不平凡时。