DeclContext::addHiddenDecl vs NamedDecl::isHidden

Hi,
   Is there any particular reason DeclContext::addHiddenDecl to not call NamedDecl::setHidden() on the added declaration?
   It feels like an inconsistency to me, because one can add a 'hidden' NamedDecl and later on to call removeDecl. In that case the DeclContext would assert because the name wasn't found in the lookup table. Is there something I missed?
Thanks,
Vassil

Hi,
  Is there any particular reason DeclContext::addHiddenDecl to not call
NamedDecl::setHidden() on the added declaration?

Yes. addHiddenDecl doesn't make a declaration hidden, it adds it without
making it visible. This can be part of the process of making a declaration
visible... or not. It doesn't make any sense for this to mark the
declaration as hidden. (Also, declarations marked as hidden are still in
the name lookup structures, so these mean different things.)

  It feels like an inconsistency to me, because one can add a 'hidden'
NamedDecl and later on to call removeDecl. In that case the DeclContext
would assert because the name wasn't found in the lookup table. Is there
something I missed?

removeDecl is only used in very restricted circumstances, so this isn't a
problem in practice. Nor does it check whether the declaration is marked as
'hidden' -- that doesn't affect whether the name appears in the lookup
table anyway, so wouldn't be a sensible check.

Thanks for the clarification. In our context we use removeDecl a lot. For example, we need to ‘rollback’ for example the last ‘n’ decls. Thus for us the consistency of that interface is very important. Independent on that that part of removeDecl is not very clear to me, (DeclBase.cpp)01091 StoredDeclsMap *Map = getPrimaryContext()->LookupPtr.getPointer(); (DeclBase.cpp)01092 if (!Map) return; how that is supposed to work with out-of-line definitions, where the primary context of the lexical context != primary context of the ‘semantic’/‘lookup’ context. Eg: class MyClass { void f(); } MyClass::f() {} // we want to remove that out-of-line definition. Shouldn’t like 01091 be smth like: StoredDeclsMap *Map = D->getDeclContext()->getPrimaryContext()->LookupPtr.getPointer(); Many thanks, Vassil