Iterating redeclared DeclContexts

Hi folks,

I'm hacking on an implementation of namespaces for Objective-C, which
you can follow here:
https://github.com/kylesluder/objc-namespaces/tree/develop

While extending DeclContext to cover ObjC namespaces, I noticed that
DeclContext::collectAllContexts() specifically only works on
NamespaceDecls.

The log attached to that commit explicitly calls out
Redeclarable<NamespaceDecl>, so I'm curious why the code checks for
NamespaceDecl rather than working for all Redeclarable<> subtypes.

This is relevant to me, as I would like my namespaces to be redeclarable
as well. :slight_smile: And presumably, if another kind of redeclarable DeclContext
comes along, it too would want to participate. (In fact, I'm surprised
this doesn't already cause problems with ObjCInterfaceDecl.)

Would the project be interested in a patch that made this work with all
classes that derive from Redeclarable<>?

--Kyle Sluder

None of the other Redeclarable DeclContexts we currently have want this behaviour. (And in the presence of C++ modules, it wouldn’t be correct - in that case, we only want to perform lookups into the class definition, not into any other class definition we’ve merged with it).

I suggest you just special-case the two forms of namespace. (Or use Objective-C++ ;).)

None of the other Redeclarable DeclContexts we currently have want this behaviour. (And in the presence of C++ modules, it wouldn’t be correct - in that case, we only want to perform lookups into the class definition, not into any other class definition we’ve merged with it).

Ah, I see. Perhaps the doc comment could use some enhancement. (Or maybe I just didn’t understand the implications the first time through.)

I suggest you just special-case the two forms of namespace. (Or use Objective-C++ ;).)

It’s probably due to my lack of C++ experience, but I find it weird to have this special-casing logic in the superclass. Is there a reason not to make this a virtual method?

As for Objective-C++, it doesn’t provide this feature, and since ObjC namespaces have runtime implications, my design is completely independent of ObjC++.

–Kyle Sluder