问题描述
在C ++中,noexcept如何更改程序集?我在Godbolt中尝试了一些小的功能,但是程序集未更改.
How does noexcept in C++ change the assembly? I tried a bit with small functions, in godbolt, but the assembly did not change.
float pi()
//noexcept // no difference
{ return 3.14; }
int main(){
float b{0};
b = pi();
return 0;
}
我正在寻找一个最小的工作示例,在其中我可以看到由于noexcept
而导致的装配更改.
I am looking for a minimal working example, where I can see a change in the assembly due to noexcept
.
推荐答案
可以构建非常简单的示例/a>直接涉及析构函数,而不是对noexcept
状态的内省:
Pretty simple examples can be constructed that involve destructors directly rather than introspection on noexcept
status:
void a(int);
void b() noexcept;
void c(int i) {
struct A {
int i;
~A() {a(i);}
} a={i};
b();
a.i=1;
}
在这里,由于析构函数无法观察到,因此noexcept
允许忽略调用方中a
的初始化.
Here, the noexcept
allows the initialization of a
in the caller to be ignored, since the destructor cannot observe it.
struct B {~B();};
void f();
void g() noexcept {
B b1;
f();
B b2;
}
在这里,noexcept
允许省略被呼叫者抛出的帧信息.这取决于(非常常见)的决定,即在调用std::terminate
时不展开堆栈.
Here, the noexcept
allows the omission of frame information needed in case the callee throws. This depends on the (very common) decision to not unwind the stack when calling std::terminate
.
这篇关于C ++中的noexcept如何更改程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!