【发布时间】:2014-11-20 18:40:03
【问题描述】:
这是一件我认为不应该发生的非常奇怪的事情:
UnicodeString test = "abc";
try
{
try
{
int a = 123;
return a; // This seems to produce a problem with "test" variable scope
}
catch (Exception &e)
{
// Some exception handler here
}
}
__finally
{
// At this point the "test" variable should still be in scope???
test = "xyz"; // PROBLEM here - test is NULL instead of "abc"! Why?
}
如果我删除try-catch 块中的return a;,测试变量仍然被定义。在上述构造之后,UnicodeString 似乎超出范围是否有特殊原因?这是 C++ Builder 2010 的错误吗?我知道 return 从函数返回,但它仍应在 __finally 块中保留变量范围,不是吗?
【问题讨论】:
-
这也发生在 C++Builder XE5, FWIW 上。
-
昨天在 Embarcadero 论坛上讨论了同样的问题,我提供了对编译器正在做什么的分析:Why is UnicodeString losing scope in this example?。
-
堆栈展开在 bcc32 中一直存在问题;例如this bug 已经存在多年了,现在仍然存在
标签: scope c++builder try-catch-finally