www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Goto into catch blocks

reply Iain Buclaw <ibuclaw ubuntu.com> writes:
I have been merging Phobos that got released with the latest DMD release into
GDC. And couldn't help but notice this nostalgic error I implemented a while
back:

    std/format.d:1520: Error: cannot goto into catch block


Line of concern in phobos:
https://github.com/D-Programming-Language/phobos/blob/master/std/format.d#L1539

Part of spec which error implements:
http://www.digitalmars.com/d/2.0/statement.html#GotoStatement

I have discussed such code before and why it should be disallowed:
http://www.digitalmars.com/d/archives/digitalmars/D/Behaviour_of_goto_into_catch_blocks._116908.html


And I have raised a pull request (though I seem to recall I had commit access
granted a while back - though this was before the move to github):
https://github.com/D-Programming-Language/phobos/pull/253


Regards
Iain
Sep 12 2011
next sibling parent reply dsimcha <dsimcha yahoo.com> writes:
== Quote from Iain Buclaw (ibuclaw ubuntu.com)'s article
 I have been merging Phobos that got released with the latest DMD release into
 GDC.
Great. I was wondering what happened here since you usually merge Phobos and DMD at the same time, and I'm very excited that the last few showstopper bugs got fixed and GDC may actually be usable now.
 And I have raised a pull request (though I seem to recall I had commit access
 granted a while back - though this was before the move to github):
 https://github.com/D-Programming-Language/phobos/pull/253
Generally you should use pull requests even if you have commit access, so that the code gets reviewed by at least one other person. This has led to major improvements in the code quality in Phobos. The exception is for "trivial" things. There's a little disagreement about where the line should be drawn. I draw it at simple one- or a few-liner bug fixes in code I understand well, and reverting recent changes that cause build problems. These and anything simpler, I push directly. Anything more complicated, I think review is worthwhile. Others seem to think that basically any change to actual code is non-trivial, though I think this is excessively bureaucratic and would only follow it if there was a very strong consensus and a written rule in our dev guidelines.
Sep 12 2011
parent Iain Buclaw <ibuclaw ubuntu.com> writes:
== Quote from dsimcha (dsimcha yahoo.com)'s article
 == Quote from Iain Buclaw (ibuclaw ubuntu.com)'s article
 I have been merging Phobos that got released with the latest DMD release into
 GDC.
Great. I was wondering what happened here since you usually merge Phobos and DMD at the same time, and I'm very excited that the last few showstopper bugs got fixed and GDC may actually be usable now.
A very particular change to arraytypes in the frontend was the reason for that. :o)
 And I have raised a pull request (though I seem to recall I had commit access
 granted a while back - though this was before the move to github):
 https://github.com/D-Programming-Language/phobos/pull/253
Generally you should use pull requests even if you have commit access, so that the code gets reviewed by at least one other person. This has led to major improvements in the code quality in Phobos. The exception is for "trivial" things. There's a little disagreement about where the line should be drawn. I draw it at simple one- or a few-liner bug fixes in code I understand well, and reverting recent changes that cause build problems. These and anything simpler, I push directly. Anything more complicated, I think review is worthwhile. Others seem to think that basically any change to actual code is non-trivial, though I think this is excessively bureaucratic and would only follow it if there was a very strong consensus and a written rule in our dev guidelines.
OK, thanks.
Sep 12 2011
prev sibling next sibling parent "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Monday, September 12, 2011 15:27 Iain Buclaw wrote:
 I have been merging Phobos that got released with the latest DMD release
 into GDC. And couldn't help but notice this nostalgic error I implemented
 a while back:
 
 std/format.d:1520: Error: cannot goto into catch block
 
 
 Line of concern in phobos:
 https://github.com/D-Programming-Language/phobos/blob/master/std/format.d#L
 1539
 
 Part of spec which error implements:
 http://www.digitalmars.com/d/2.0/statement.html#GotoStatement
 
 I have discussed such code before and why it should be disallowed:
 http://www.digitalmars.com/d/archives/digitalmars/D/Behaviour_of_goto_into_
 catch_blocks._116908.html
 
 
 And I have raised a pull request (though I seem to recall I had commit
 access granted a while back - though this was before the move to github):
 https://github.com/D-Programming-Language/phobos/pull/253
Regardless of whether you have commit access, anything other than really trivial changes (such as updates to the changelog) should still go through pull requests. At this point having commit access is more about being able to merge in other people's pull requests that have been adequately reviewed than being able to commit your own changes. However, if you want commit access again, then ping Walter about it, and he should be able to give you commit access. - Jonathan M Davis
Sep 12 2011
prev sibling parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 09/13/2011 12:27 AM, Iain Buclaw wrote:
 I have been merging Phobos that got released with the latest DMD release into
 GDC. And couldn't help but notice this nostalgic error I implemented a while
back:

      std/format.d:1520: Error: cannot goto into catch block


 Line of concern in phobos:
 https://github.com/D-Programming-Language/phobos/blob/master/std/format.d#L1539

 Part of spec which error implements:
 http://www.digitalmars.com/d/2.0/statement.html#GotoStatement
Where does it say that a goto into a catch block is categorically banned? It only says that a goto cannot skip a variable initialization. catch(Type){} and catch{} are valid forms too. Neither one contains a declaration. Sure, usually a goto into a catch block means that someone is abusing exceptions for regular control flow, but if you just want a quick and dirty hack, or if a third-party API forces you to, I don't think the language should stand in your way.
Sep 12 2011
parent reply Iain Buclaw <ibuclaw ubuntu.com> writes:
== Quote from Timon Gehr (timon.gehr gmx.ch)'s article
 On 09/13/2011 12:27 AM, Iain Buclaw wrote:
 I have been merging Phobos that got released with the latest DMD release into
 GDC. And couldn't help but notice this nostalgic error I implemented a while
back:

      std/format.d:1520: Error: cannot goto into catch block


 Line of concern in phobos:
 https://github.com/D-Programming-Language/phobos/blob/master/std/format.d#L1539

 Part of spec which error implements:
 http://www.digitalmars.com/d/2.0/statement.html#GotoStatement
Where does it say that a goto into a catch block is categorically banned? It only says that a goto cannot skip a variable initialization.
Which it does in this situation (what is initialising UtfException e?).
 catch(Type){}
 and
 catch{}
 are valid forms too. Neither one contains a declaration.
 Sure, usually a goto into a catch block means that someone is abusing
 exceptions for regular control flow, but if you just want a quick and
 dirty hack, or if a third-party API forces you to, I don't think the
 language should stand in your way.
In terms of codegen for such, you will still pass through any cleanup that was generated when the catch block ends (ie: builtin unwind routines). Think of your latter example as being rewritten as: try { // questionable user code } catch { try { // user catch code } finally { // compiler generated clean-up block } } Regards Iain
Sep 12 2011
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 09/13/2011 08:58 AM, Iain Buclaw wrote:
 == Quote from Timon Gehr (timon.gehr gmx.ch)'s article
 On 09/13/2011 12:27 AM, Iain Buclaw wrote:
 I have been merging Phobos that got released with the latest DMD release into
 GDC. And couldn't help but notice this nostalgic error I implemented a while
back:

       std/format.d:1520: Error: cannot goto into catch block


 Line of concern in phobos:
 https://github.com/D-Programming-Language/phobos/blob/master/std/format.d#L1539

 Part of spec which error implements:
 http://www.digitalmars.com/d/2.0/statement.html#GotoStatement
Where does it say that a goto into a catch block is categorically banned? It only says that a goto cannot skip a variable initialization.
Which it does in this situation (what is initialising UtfException e?).
 catch(Type){}
 and
 catch{}
 are valid forms too. Neither one contains a declaration.
 Sure, usually a goto into a catch block means that someone is abusing
 exceptions for regular control flow, but if you just want a quick and
 dirty hack, or if a third-party API forces you to, I don't think the
 language should stand in your way.
In terms of codegen for such, you will still pass through any cleanup that was generated when the catch block ends (ie: builtin unwind routines).
OK, that is a reason. Thanks. What exactly is done in the cleanup block?
Sep 13 2011