<div dir="ltr">I think this is a corner case bug of current dmd parser.<div><br></div><div style>Kenji Hara</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/5/28 monarch_dodra <span dir="ltr"><<a href="mailto:monarchdodra@gmail.com" target="_blank">monarchdodra@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have created before two threads about the weird semantics of labeled block statements. In a word: putting a label before a block means that block does not create a scope, and the variables created inside that scope will "leak" to the outside of said scope. I've found this to be problematic on several points:<br>

<br>
1. No use case for this<br>
2. You can accidentally break code by placing a label before a block (but without meaning to label the actual block)<br>
3. Deviates from C.<br>
<br>
What kind of bothers me most is the combination 1 & 3: Why??? I've complained about this before, and the answer was: "According to spec", but to the question "why are the specs like this", I have yet to get an answer.<br>

<br>
----------------<br>
The reason I'm bringing this up (again), is that it bit me in the ass very recently. According to TDPL:<br>
<br>
"If a numeric expression compiles in the C language and also compiles in D, its<br>
type will be the same in both languages (note that not all C expressions must be<br>
accepted by D)."<br>
<br>
Followed by<br>
<br>
"Rule 1 makes things just a tad more complicated than they would otherwise be, but D overlaps enough with C and C++ to inspire people to simply copy and paste entire functions into D programs. Now it’s all right if D occasionally refuses to compile certain constructs for safety or portability reasons; but if it compiled that 2000-line encryption package and ran it with different results, life would definitely not be good for the hapless victim."<br>

<br>
So basically, this is saying "If your C code compiles in D, you'll get the same result. I guarantee it :)"<br>
<br>
Here's a (reduced) C program:<br>
<br>
----<br>
int i = 3;<br>
<br>
void main()<br>
{<br>
  {<br>
    int some_condition = 1;<br>
    if ( some_condition )<br>
      goto block_end;<br>
<br>
    /* dummy code */<br>
  } block_end:<br>
<br>
  {<br>
    int i = 7;<br>
    printf("%i", i);<br>
  }<br>
<br>
  printf("%i", i);<br>
}<br>
----<br>
C prints: "70"<br>
D prints: "77"<br>
<br>
Oops!<br>
<br>
I realize 99% of people don't use goto or labels too much, but this doesn't mean it shouldn't be addressed. For me, D has been about being a "smooth experience", and this makes so little sense to me it infuriates me.<br>

<br>
I don't see how this could help anyone, but I do see how it can create bugs, and these kinds of cases are what D strives to avoid. "Fixing" would probably break nothing.<br>
<br>
-------------------<br>
I'd like to make a push to get the specs changed in regards to this. I'd like to get others' opinion on the matter, in particular, if anybody can think of a rationale for the current behavior. And if there is no rationale, how much support there is for changing it. (in which case I'll file the corresponding ER).<br>

</blockquote></div><br></div>