C ++中的noexcept如何更改程序集? [英] How does noexcept in C++ change the assembly?

查看:133
本文介绍了C ++中的noexcept如何更改程序集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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如何更改程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆