summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDeclCXX.cpp
diff options
context:
space:
mode:
authorSebastian Redl <sebastian.redl@getdesigned.at>2009-11-23 15:34:23 +0000
committerSebastian Redl <sebastian.redl@getdesigned.at>2009-11-23 15:34:23 +0000
commita6602e9e2a603dcd750d443e7b8fd60f1afc2a89 (patch)
tree16af897f55f3a56318463a17707143e9d032bf5e /clang/lib/Sema/SemaDeclCXX.cpp
parent378e1923b6a5553ba7aa3d24e6cdd6b80064470b (diff)
downloadbcm5719-llvm-a6602e9e2a603dcd750d443e7b8fd60f1afc2a89.tar.gz
bcm5719-llvm-a6602e9e2a603dcd750d443e7b8fd60f1afc2a89.zip
Let using directives refer to namespace aliases. Fixes PR5479.
llvm-svn: 89657
Diffstat (limited to 'clang/lib/Sema/SemaDeclCXX.cpp')
-rw-r--r--clang/lib/Sema/SemaDeclCXX.cpp31
1 files changed, 14 insertions, 17 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 3ff9144cc21..58fe97a7e51 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -2722,6 +2722,14 @@ Sema::DeclPtrTy Sema::ActOnStartNamespaceDef(Scope *NamespcScope,
return DeclPtrTy::make(Namespc);
}
+/// getNamespaceDecl - Returns the namespace a decl represents. If the decl
+/// is a namespace alias, returns the namespace it points to.
+static inline NamespaceDecl *getNamespaceDecl(NamedDecl *D) {
+ if (NamespaceAliasDecl *AD = dyn_cast_or_null<NamespaceAliasDecl>(D))
+ return AD->getNamespace();
+ return dyn_cast_or_null<NamespaceDecl>(D);
+}
+
/// ActOnFinishNamespaceDef - This callback is called after a namespace is
/// exited. Decl is the DeclTy returned by ActOnStartNamespaceDef.
void Sema::ActOnFinishNamespaceDef(DeclPtrTy D, SourceLocation RBrace) {
@@ -2753,9 +2761,9 @@ Sema::DeclPtrTy Sema::ActOnUsingDirective(Scope *S,
return DeclPtrTy();
if (!R.empty()) {
- NamedDecl *NS = R.getFoundDecl();
- // FIXME: Namespace aliases!
- assert(isa<NamespaceDecl>(NS) && "expected namespace decl");
+ NamedDecl *Named = R.getFoundDecl();
+ assert((isa<NamespaceDecl>(Named) || isa<NamespaceAliasDecl>(Named))
+ && "expected namespace decl");
// C++ [namespace.udir]p1:
// A using-directive specifies that the names in the nominated
// namespace can be used in the scope in which the
@@ -2768,18 +2776,15 @@ Sema::DeclPtrTy Sema::ActOnUsingDirective(Scope *S,
// Find enclosing context containing both using-directive and
// nominated namespace.
+ NamespaceDecl *NS = getNamespaceDecl(Named);
DeclContext *CommonAncestor = cast<DeclContext>(NS);
while (CommonAncestor && !CommonAncestor->Encloses(CurContext))
CommonAncestor = CommonAncestor->getParent();
- UDir = UsingDirectiveDecl::Create(Context,
- CurContext, UsingLoc,
- NamespcLoc,
+ UDir = UsingDirectiveDecl::Create(Context, CurContext, UsingLoc, NamespcLoc,
SS.getRange(),
(NestedNameSpecifier *)SS.getScopeRep(),
- IdentLoc,
- cast<NamespaceDecl>(NS),
- CommonAncestor);
+ IdentLoc, Named, CommonAncestor);
PushUsingDirective(S, UDir);
} else {
Diag(IdentLoc, diag::err_expected_namespace_name) << SS.getRange();
@@ -3006,14 +3011,6 @@ NamedDecl *Sema::BuildUsingDeclaration(Scope *S, AccessSpecifier AS,
return UD;
}
-/// getNamespaceDecl - Returns the namespace a decl represents. If the decl
-/// is a namespace alias, returns the namespace it points to.
-static inline NamespaceDecl *getNamespaceDecl(NamedDecl *D) {
- if (NamespaceAliasDecl *AD = dyn_cast_or_null<NamespaceAliasDecl>(D))
- return AD->getNamespace();
- return dyn_cast_or_null<NamespaceDecl>(D);
-}
-
Sema::DeclPtrTy Sema::ActOnNamespaceAliasDef(Scope *S,
SourceLocation NamespaceLoc,
SourceLocation AliasLoc,
OpenPOWER on IntegriCloud