diff options
| author | John McCall <rjmccall@apple.com> | 2009-12-16 02:06:49 +0000 |
|---|---|---|
| committer | John McCall <rjmccall@apple.com> | 2009-12-16 02:06:49 +0000 |
| commit | 0db42252f75f3baa72fe73ab0dfb7ba6e1bd2e29 (patch) | |
| tree | 0c07e8752ec149b3970e2092bd5022157cebc505 /clang/lib/Sema | |
| parent | 85dabae6ad94925a9ec99cdf375c4e8768ea0e03 (diff) | |
| download | bcm5719-llvm-0db42252f75f3baa72fe73ab0dfb7ba6e1bd2e29.tar.gz bcm5719-llvm-0db42252f75f3baa72fe73ab0dfb7ba6e1bd2e29.zip | |
Successive anonymous namespaces name the same scope. I misinterpreted the
standard the last time. Fixes PR5766.
llvm-svn: 91493
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 49 |
1 files changed, 35 insertions, 14 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index a70841f536d..08edb117e87 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -2748,6 +2748,28 @@ Sema::DeclPtrTy Sema::ActOnStartNamespaceDef(Scope *NamespcScope, PushOnScopeChains(Namespc, DeclRegionScope); } else { // Anonymous namespaces. + assert(Namespc->isAnonymousNamespace()); + CurContext->addDecl(Namespc); + + // Link the anonymous namespace into its parent. + NamespaceDecl *PrevDecl; + DeclContext *Parent = CurContext->getLookupContext(); + if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(Parent)) { + PrevDecl = TU->getAnonymousNamespace(); + TU->setAnonymousNamespace(Namespc); + } else { + NamespaceDecl *ND = cast<NamespaceDecl>(Parent); + PrevDecl = ND->getAnonymousNamespace(); + ND->setAnonymousNamespace(Namespc); + } + + // Link the anonymous namespace with its previous declaration. + if (PrevDecl) { + assert(PrevDecl->isAnonymousNamespace()); + assert(!PrevDecl->getNextNamespace()); + Namespc->setOriginalNamespace(PrevDecl->getOriginalNamespace()); + PrevDecl->setNextNamespace(Namespc); + } // C++ [namespace.unnamed]p1. An unnamed-namespace-definition // behaves as if it were replaced by @@ -2765,20 +2787,19 @@ Sema::DeclPtrTy Sema::ActOnStartNamespaceDef(Scope *NamespcScope, // declarations semantically contained within an anonymous // namespace internal linkage. - assert(Namespc->isAnonymousNamespace()); - CurContext->addDecl(Namespc); - - UsingDirectiveDecl* UD - = UsingDirectiveDecl::Create(Context, CurContext, - /* 'using' */ LBrace, - /* 'namespace' */ SourceLocation(), - /* qualifier */ SourceRange(), - /* NNS */ NULL, - /* identifier */ SourceLocation(), - Namespc, - /* Ancestor */ CurContext); - UD->setImplicit(); - CurContext->addDecl(UD); + if (!PrevDecl) { + UsingDirectiveDecl* UD + = UsingDirectiveDecl::Create(Context, CurContext, + /* 'using' */ LBrace, + /* 'namespace' */ SourceLocation(), + /* qualifier */ SourceRange(), + /* NNS */ NULL, + /* identifier */ SourceLocation(), + Namespc, + /* Ancestor */ CurContext); + UD->setImplicit(); + CurContext->addDecl(UD); + } } // Although we could have an invalid decl (i.e. the namespace name is a |

