C++中的noexcept如何改变程序集?
How does noexcept in C++ change the assembly?
C++中的noexcept如何改变汇编?我在 godbolt 中尝试了一些小函数,但是 the assembly did not change.
float pi()
//noexcept // no difference
{ return 3.14; }
int main(){
float b{0};
b = pi();
return 0;
}
我正在寻找一个最小的工作示例,我可以在其中看到由于 noexcept
.
而导致的程序集更改
非常简单的示例 can be constructed 直接涉及析构函数而不是对 noexcept
状态进行内省:
void a(int);
void b() noexcept;
void c(int i) {
struct A {
int i;
~A() {a(i);}
} a={i};
b();
a.i=1;
}
此处,noexcept
允许忽略 caller 中 a
的初始化,因为析构函数无法观察到它。
struct B {~B();};
void f();
void g() noexcept {
B b1;
f();
B b2;
}
此处,noexcept
允许省略 callee 抛出时所需的帧信息。这取决于调用 std::terminate
.
时不展开堆栈的(非常常见的)决定
C++中的noexcept如何改变汇编?我在 godbolt 中尝试了一些小函数,但是 the assembly did not change.
float pi()
//noexcept // no difference
{ return 3.14; }
int main(){
float b{0};
b = pi();
return 0;
}
我正在寻找一个最小的工作示例,我可以在其中看到由于 noexcept
.
非常简单的示例 can be constructed 直接涉及析构函数而不是对 noexcept
状态进行内省:
void a(int);
void b() noexcept;
void c(int i) {
struct A {
int i;
~A() {a(i);}
} a={i};
b();
a.i=1;
}
此处,noexcept
允许忽略 caller 中 a
的初始化,因为析构函数无法观察到它。
struct B {~B();};
void f();
void g() noexcept {
B b1;
f();
B b2;
}
此处,noexcept
允许省略 callee 抛出时所需的帧信息。这取决于调用 std::terminate
.