简体   繁体   English

DMD不强制限制foreach

[英]DMD doesn't force restrictions on foreach

According to the section "Foreach Restrictions" at http://dlang.org/statement.html the following code 根据http://dlang.org/statement.html上的“ Foreach限制”部分,以下代码

int[] a;
int[] b;
foreach (int i; a) { 
    a = null; // error
    a.length += 10; // error 
    a = b; // error 
}
a = null; // ok

should error. 应该出错。

But it doesn't for me when using 2.063.2 nor master. 但这在我使用2.063.2或master时不适合我。

Is this a regression bug? 这是回归错误吗?

It was probably never implemented as an actual error. 它可能从未实现为实际错误。 I don't see an open bug, but I'm bad at searching bugzilla... regardless though, I'm sure the spec simply was never implemented to actually show the error, leaving it as undefined behavior if you actually do it. 我看不到一个开放的错误,但是我很难搜索bugzilla ...尽管,我确信该规范根本没有实现为实际显示错误,如果您实际执行,则将其保留为未定义的行为。

In several places, the D documentation says something is an error, without the compiler actually checking for this. 在很多地方,D文档都说出了一个错误,而编译器并未实际检查。 C and C++ would probably use the term 'undefined behavior' instead of 'error'. C和C ++可能会使用术语“未定义的行为”而不是“错误”。 In C and C++, such a program is valid, you just have no idea what it does. 在C和C ++中,这样的程序是有效的,您根本不知道它做什么。 In D, it is simply not considered a valid program. 在D中,它根本不被视为有效程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM