On Sep 1, 2009, at 10:46 AM, Douglas Gregor wrote: >> On Sep 1, 2009, at 10:31 AM, Douglas Gregor wrote: >> >>>> Can we make pointer comparisons of DeclContext objects illegal >>>> (e.g., a private operator== method)? >>> >>> Sadly, no :( >>> >>> An overloaded operator has to have at least on parameter of class >>> or enumeration type (or reference to one of those). The signature >>> we would need, e.g., >>> >>> private: >>> friend bool operator==(DeclContext *, DeclContext *); >>> >>> does not qualify. >>> >>> - Doug >> >> Ah, that's right. Would it be possible to do this if we were using >> DeclContext& instead of DeclContext* in all places where we >> referred to DeclContext objects? > > > Yes, although I fear that might be a bit awkward to use. We're often > walking parent contexts, lookup contexts, etc., so that DeclContext& > wouldn't be appropriate. Now, we could do a whole-sale replacement > of DeclContext * for a new smart pointer DeclContextPtr... then we > can do whatever we want, including make operator== do the right thing.
Although I think that many would think this was unnecessary overhead, I really like the smart pointer idea. It nicely defines away a category of insidious bugs. _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
