Author: rjmccall Date: Tue Feb 16 00:53:13 2010 New Revision: 96335 URL: http://llvm.org/viewvc/llvm-project?rev=96335&view=rev Log: Support local namespace aliases and permit them to be instantiated.
Modified: cfe/trunk/include/clang/AST/DeclCXX.h cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp cfe/trunk/test/SemaCXX/namespace-alias.cpp Modified: cfe/trunk/include/clang/AST/DeclCXX.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=96335&r1=96334&r2=96335&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/DeclCXX.h (original) +++ cfe/trunk/include/clang/AST/DeclCXX.h Tue Feb 16 00:53:13 2010 @@ -1628,6 +1628,16 @@ return const_cast<NamespaceAliasDecl*>(this)->getNamespace(); } + /// Returns the location of the alias name, i.e. 'foo' in + /// "namespace foo = ns::bar;". + SourceLocation getAliasLoc() const { return AliasLoc; } + + /// Returns the location of the 'namespace' keyword. + SourceLocation getNamespaceLoc() const { return getLocation(); } + + /// Returns the location of the identifier in the named namespace. + SourceLocation getTargetNameLoc() const { return IdentLoc; } + /// \brief Retrieve the namespace that this alias refers to, which /// may either be a NamespaceDecl or a NamespaceAliasDecl. NamedDecl *getAliasedNamespace() const { return Namespace; } Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=96335&r1=96334&r2=96335&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Feb 16 00:53:13 2010 @@ -3691,7 +3691,7 @@ (NestedNameSpecifier *)SS.getScopeRep(), IdentLoc, R.getFoundDecl()); - CurContext->addDecl(AliasDecl); + PushOnScopeChains(AliasDecl, S); return DeclPtrTy::make(AliasDecl); } Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=96335&r1=96334&r2=96335&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Tue Feb 16 00:53:13 2010 @@ -43,6 +43,7 @@ // clang/AST/DeclNodes.def. Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D); Decl *VisitNamespaceDecl(NamespaceDecl *D); + Decl *VisitNamespaceAliasDecl(NamespaceAliasDecl *D); Decl *VisitTypedefDecl(TypedefDecl *D); Decl *VisitVarDecl(VarDecl *D); Decl *VisitFieldDecl(FieldDecl *D); @@ -126,6 +127,21 @@ return D; } +Decl * +TemplateDeclInstantiator::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { + NamespaceAliasDecl *Inst + = NamespaceAliasDecl::Create(SemaRef.Context, Owner, + D->getNamespaceLoc(), + D->getAliasLoc(), + D->getNamespace()->getIdentifier(), + D->getQualifierRange(), + D->getQualifier(), + D->getTargetNameLoc(), + D->getNamespace()); + Owner->addDecl(Inst); + return Inst; +} + Decl *TemplateDeclInstantiator::VisitTypedefDecl(TypedefDecl *D) { bool Invalid = false; TypeSourceInfo *DI = D->getTypeSourceInfo(); Modified: cfe/trunk/test/SemaCXX/namespace-alias.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/namespace-alias.cpp?rev=96335&r1=96334&r2=96335&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/namespace-alias.cpp (original) +++ cfe/trunk/test/SemaCXX/namespace-alias.cpp Tue Feb 16 00:53:13 2010 @@ -62,3 +62,24 @@ func(); } } + +namespace K { + namespace KA { void func(); } + + void f() { + namespace KB = KA; + KB::func(); + } + + template <class T> void g() { + namespace KC = KA; + KC::func(); + } + template void g<int>(); + template void g<long>(); + + void h() { + KB::func(); // expected-error {{undeclared identifier 'KB'}} + KC::func(); // expected-error {{undeclared identifier 'KC'}} + } +} _______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits