什么是“recursive_init_error”例外?
我决定使用计算的 goto 和本地静态进行测试,
void g() { std::cout << "init "; }
void f() {
int z = 0;
y: z++;
static int x =
(g(), z == 1 ? ({ goto *&&y; 0; }) : 0);
}
int main() { f(); std::cout << "!"; f(); }
我想看看输出是否为“init init!”。但令我惊讶的是,我没有得到该输出,而是 GCC 优雅地处理了它,在运行时输出:
init terminated by recursive_init_error: exception
那个异常是什么?这是标准例外吗? C++03 还是 C++0x?感谢您的任何解释。
I decided to do a test with computed gotos and local statics
void g() { std::cout << "init "; }
void f() {
int z = 0;
y: z++;
static int x =
(g(), z == 1 ? ({ goto *&&y; 0; }) : 0);
}
int main() { f(); std::cout << "!"; f(); }
I wanted to see whether the output would be "init init !". But to my surprise I didn't get that output, but instead GCC handled it gracefully, outputting at runtime:
init terminated by recursive_init_error: exception
What's that exception? Is it a Standard exception? C++03 or C++0x? Thanks for any explanation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是由 C++03 §6.7/4 中所述引起的:
在这种情况下,GCC 会抛出异常。这是关于它的一些文档。
C++11 更新:C++11 中在有关递归情况的文本之前添加了以下措辞:
不会改变这里的问题,但会在没有递归时使此构造线程安全。
It's caused by what is stated in C++03 §6.7/4:
GCC throws an exception in that case. Here's some documentation about it.
C++11 update: The following wording was added in C++11, just before the text about the recursive case:
Doesn't change the problem here, but does make this construct thread-safe when there is no recursion.