[cfe-dev] UsingDirectiveDecl inconsistently (not) added to their DeclContext.
John McCall
rjmccall at apple.com
Tue Sep 4 10:21:22 PDT 2012
On Aug 6, 2012, at 7:30 AM, Enea Zaffanella wrote:
> We are observing an inconsistency (affecting our AST visitors) in the
> addition of UsingDirectiveDecl to their DeclContext.
>
> When parsing a using directive, it gets added to its DeclContext only if
> it is NOT a function/method:
>
> ===================== SemaDeclCXX.cpp
> void Sema::PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir) {
> // If the scope has an associated entity and the using directive is at
> // namespace or translation unit scope, add the UsingDirectiveDecl into
> // its lookup structure so qualified name lookup can find it.
> DeclContext *Ctx = static_cast<DeclContext*>(S->getEntity());
> if (Ctx && !Ctx->isFunctionOrMethod())
> Ctx->addDecl(UDir);
> =====================
>
>
> However, when such a using declaration is subject to template
> instantiations, it is unconditionally added to its DeclContext, no
> matter if it is a function/method or not:
>
> ===================== SemaTemplateInstantiateDecl.cpp
> Decl
> *TemplateDeclInstantiator::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
> // Using directives are never dependent (and never contain any types or
> // expressions), so they require no explicit instantiation work.
>
> UsingDirectiveDecl *Inst
> = UsingDirectiveDecl::Create(SemaRef.Context, Owner, D->getLocation(),
> D->getNamespaceKeyLocation(),
> D->getQualifierLoc(),
> D->getIdentLocation(),
> D->getNominatedNamespace(),
> D->getCommonAncestor());
> Owner->addDecl(Inst);
> =====================
>
> Therefore, when visiting the instantiated DeclContext we will see more
> declarations than when visiting its instantiation pattern.
> We would like to remove this inconsistency, but it is unclear to us
> which is the right fix to apply: should we always add the using
> declaration to its DeclContext or should we repeat the check for
> function/method when instantiating?
Repeat the check; I don't see any value to having the UsingDirectiveDecl
in the DC for a function.
John.
More information about the cfe-dev
mailing list