D15694: Make implicit fallthroughs a compiler error, remove unneeded breaks

René J.V. Bertin noreply at phabricator.kde.org
Mon Sep 24 09:27:43 BST 2018


rjvbb added a comment.


  >   As discussed earlier, switch statements do have a weird syntax and I'm completely with you if you don't like it. They are basically a glorified `goto` cascade. The case labels actually behave like `goto` labels in a lot of ways, which is the basis of oddities like Duff's device
  
  I can't say I don't like switch statements, I've done too much low-level C coding wishing I had had more justification to learn assembly, and for more powerful computed goto functionality (which a switch statement is, in a sense). My gripe is more with having to change my habits in ways I don't necessarily agree with entirely, and which might interfere with coding in other contexts.
  
  >   Like @kossebau, I'm not sure these obvious cases occur so often in practice.
  
  It may not in KDevelop's code, but that's not all that all of us work on. Coding style and guidelines for KDevelop itself could reflect good practice you'd like to advocate in general.
  
  >   That isn't happening in your example, the cases are actually handled differently. One case, after some preprocessing, "falls through" to the second.
  
  Yes and no. The example was meant to show a context where you have some sort of common denominator; think inheritance and a routine that does something like initialisation, where each case represents a less specialised version. Does that make it sound less exotic.
  Re. Duff's device: I'm pretty certain I've seen a comparably obfuscated bit of code recently, possibly somewhere in the Qt code.
  
  >   But it's probably a bit too invasive for existing code bases, compared to adding a few annotations. 
  
  Yes, that's why I used the concept of encouraging people ;)
  
  Now just once more about using Q_FALLTHROUGH. I've wondered (but kept mum) about code reuse elsewhere, but there's also the question how much code there is in KDevelop that doesn't require any Qt APIs? If we agree that Q_FALLTHROUGH doesn't look very nice and is temporary only
  
  Not that `[[fallthrough]]` looks so great (esp. when I'm not wearing appropriate sight correction :D) - I'd be curious to know how this will be handled in ObjC (where I think it corresponds to doing something "not-done" twice). BTW, will there be a corresponding C standard that introduces the same keyword, I'd surely hope so?! If not I do wonder if when C++ is going to introduce a switch/case version that's more on par with the version in interpreted languages that can take non-const cases...

REPOSITORY
  R32 KDevelop

REVISION DETAIL
  https://phabricator.kde.org/D15694

To: aaronpuchert, #kdevelop
Cc: rjvbb, brauch, mssola, kossebau, kdevelop-devel, glebaccon, antismap, iodelay, vbspam, geetamc, Pilzschaf, akshaydeo, surgenight, arrowd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20180924/a3ea3d1b/attachment.html>


More information about the KDevelop-devel mailing list