cast<> returning references

Jordan Rose jordan_rose at apple.com
Mon Feb 25 09:37:59 PST 2013


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".)

Jordan



More information about the cfe-commits mailing list