D. *_*ine 5 c++ g++ visual-c++
考虑以下代码:
// in main.cpp
#include <type_traits>
struct A {
A& operator=(const A&) = default;
A& operator=(A&&) = default;
};
int main() {
static_assert(std::is_pod<A>::value);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
您可以看到有一个默认的移动赋值运算符struct A
。
在msvc(VS2017)中,cl /std:c++17 main.cpp
我遇到了静态断言失败。
在g++(MinGW-W64, 8.1.0)中,使用g++ -std=c++17 main.cpp
,没有任何问题。
但是,如果我注释掉A& operator=(A&&) = default;
,两个编译器中的一切都很好。
那么,POD 类型可以有一个显式声明的默认移动赋值运算符吗?
是的,POD 类型可以有一个显式声明的默认移动赋值运算符: https://en.cppreference.com/w/cpp/named_req/PODType
这是 MSVC 中的一个错误,在编译器版本 19.26 之前出现,并在 19.27 中修复。演示: https: //gcc.godbolt.org/z/c1o5fds3x
归档时间: |
|
查看次数: |
110 次 |
最近记录: |