Skip to content

Commit 61b9b1c

Browse files
committed
Replace goto with continue
Thanks, Greg!
1 parent f10444e commit 61b9b1c

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

source/cppfront.cpp

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4814,29 +4814,9 @@ class cppfront
48144814

48154815
// Emit the initializer if it it isn't '_' (don't care) and ...
48164816
if (initializer == "_") {
4817-
// I'll walk the walk: I've said publicly that _structured_ goto is perfectly
4818-
// kosher -- it's only _unstructured_ goto that's harmful (and Dijkstra knew it),
4819-
// which means:
4820-
// - jumping into a block or statement (I'm looking at you, Duff's Device)
4821-
// - jumping backwards (that's an unstructured loop == spaghetti control flow)
4822-
// - jumping across a variable declaration (C++ already bans this)
4823-
//
4824-
// But jumping forward-and-outward, skipping no declarations, is righteous.
4825-
//
4826-
// Here, using goto is the right tool for the job, and is better code because:
4827-
// - it avoids a gratuitous extra level of nesting inside an
4828-
// 'if (initializer != "_")' block of the next 100 lines (and please don't
4829-
// start the other diatribe about that the next 100 lines should be a
4830-
// separate named function - no it shouldn't)
4831-
// - which extra indent of identical code would make GitHub's diff for this
4832-
// commit super hard to read (diff does not deal well with blocks of code
4833-
// that simply change indentation level - in fact seeing that diff without
4834-
// the goto was the tipping point to just switch to goto here)
4835-
// ... but sadly I feel the need to defend it.
4836-
//
4837-
// As Scott would say (and has said), "so sue me"
4838-
//
4839-
goto skip_initializer;
4817+
// And on to the next data member...
4818+
++object;
4819+
continue;
48404820
}
48414821

48424822
if (initializer.empty()) {
@@ -4934,8 +4914,6 @@ class cppfront
49344914
separator = ", ";
49354915
}
49364916

4937-
skip_initializer: ;
4938-
49394917
// And on to the next data member...
49404918
++object;
49414919
}

0 commit comments

Comments
 (0)