[cfe-commits] TableGen: Goodbye RTTI!
jordan_rose at apple.com
Wed Oct 10 13:02:25 PDT 2012
On Oct 10, 2012, at 11:02 , Jakob Stoklund Olesen <stoklund at 2pi.dk> wrote:
> On Oct 10, 2012, at 10:40 AM, Sean Silva <silvas at purdue.edu> wrote:
>>> - The 'kind' enums should be protected, not public.
>> My reasoning here was that it might be convenient to allow clients to
>> switch over the enum. This is also what I have documented in
>> docs/HowToSetUpLLVMStyleRTTI.rst for precisely this reason. Is there a
>> particular reason you would prefer it to be protected? I'm mostly
>> interested for the sake of updating the documentation.
> Only that it's bad OO style to switch on the leaves of a class hierarchy.
> It's bad enough that the LLVM-style RTTI requires the hierarchy to be enumerated in the base class, but at least the damage is centralized.
> A good compiler should be able to turn a chain of 'else if (isa<…>)' tests into a switch, and then you can subclass without updating all clients.
But for closed class hierarchies, missing a case in the if-chain can be more dangerous. Sure, you can put llvm_unreachable at the end, but if you forget? With the switch, the compiler tells you.
…except that in this case, Sean has the separate First/Last entries, and in addition, there probably won't be any switches over the entire hierarchy. So here I think Jakob is right.
More information about the cfe-commits