cast<> returning references

David Blaikie dblaikie at gmail.com
Mon Feb 25 09:46:00 PST 2013


On Mon, Feb 25, 2013 at 9:37 AM, Jordan Rose <jordan_rose at apple.com> wrote:
>
> On Feb 24, 2013, at 15:54 , Sean Silva <silvas at purdue.edu> wrote:
>
>> On Sun, Feb 24, 2013 at 1:53 PM, David Blaikie <dblaikie at gmail.com> wrote:
>>> & I'm just going to take this opportunity to raise an option here (& I've
>>> mentioned things like this before but they don't seem to be very popular):
>>>
>>> cast should return references, not pointers (& I'd prefer it take
>>> references, not pointers) and then we couldn't write this sort of bug*...
>>> (dyn_cast could take references too, but obviously still return pointers (or
>>> Optional<T&>, though I realize that's a bit odd))
>>
>> That would require a significant (automated) refactoring effort that I
>> don't think anyone is interested in doing (but would be a great way to
>> dogfood our own technology!).
>
> It's a cute idea, but I don't actually think it's a good one. For better or for worse, we almost never refer to AST nodes by reference, partially because the variables we use get reassigned a lot. We might become more null-correct, but it'd be a huge push to change all our interfaces to be null-correct.
>
> (I realize I'm being a bit hypocritical here, since I support pushing through const-correctness whenever possible, so maybe I should phrase this as "either we should make Clang's interfaces more null-correct first, which requires broader community sign-on, or we should just leave cast<> alone for now".)

Oh, I entirely agree with you - it would be part of a larger effort
that, as I said, no one's really been in favor of when I've mentioned
it before. I'm just being curmudgeonly.

- David




More information about the cfe-commits mailing list