SBValue::Cast actually allows casting from a struct type to another struct type. That's a little odd, C-family languages don't allow this, but we have done forever, so I don't want to remove the ability altogether. However, we can't support casting from a small structure to a larger one because in some cases - e.g. all the ConstResult types used both for expression results and for many synthetic children - we don't know where we should fetch the extra bits from. Just zero-filling them seems odd, and error seems like a better response.
This fixes a bug where when casting an expression result from a smaller type to a larger, lldb would present the memory in lldb after the ValueObject's data buffer as the value of the cast type. Again, I could have fixed that bug by expanding the data buffer to match the larger size, but I wouldn't know what to fill it with.
There were two places in the C++ formatters that were using this cast from struct to struct type to change a C++ std typedef (e.g. std::shared_ptr<Foo>::element type *) to a type that is more useful to the user (pointer to the first template argument's type). The cast from struct to struct in that case wasn't necessary, and looked weird since this really isn't an allowed C++ operation. So I also changed those to case the pointer first, then dereference the cast value.
I'm a little concerned about the API surface here. Maybe this is just my misunderstandings about ValueObject, but...
Given a ValueObjectSP (which may contain a ValueObject, ValueObjectConstResult, etc), which one of these are you supposed to call? If you call Cast, you'll get what you want. If you call DoCast, you might circumvent the safety checks that Cast is providing... but if you have something like a ValueObjectConstResult, this actually calls ValueObject::Cast which does the right thing. Am I understanding this correctly?
I also have a little confusion about which one I would call based on the names... Maybe it would make more sense to call DoCast something like CastImpl?