- 论坛徽章:
- 1
|
Scott Meyers的Effective Modern C++第29条款里面谈到:
There are thus several scenarios in which C++11's move semantics do you no good:
第三条的原文是:
Move not usable: The context in which the moving would take place requires a move operation that emits no exceptions, but that operation isn't declared noexcept.
我没有看明白这个条款是什么含义,我理解成: 如果move构造函数里面有抛出异常,那么这个move就不可用----意思move里面throw了异常就是不能编译通过?
可是我在下面的代码也能编译通过啊:
- struct S{
- S(){}
- S(S&&)noexcept{throw 1;}
- };
- int main() {
- try{
- S obj;
- S obj2(move(obj));
- }catch(...){}
- return 0;
- }
复制代码 如果noexcept是个君子协定,让编译器不要生成异常处理函数,我可以理解上面的代码,catch不到exception,所以程序异常中止。
但是Scott的这个条款似乎是在说,这样的代码就应该能编译通过?
到底怎么理解呢? |
|