diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-10-22 15:24:46 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-10-22 15:24:46 +0000 |
| commit | 412c362d9ee922585027cedf97002cba5a30a6bc (patch) | |
| tree | 2b4d97981296bd34b803f991eec67c60ecc80c53 | |
| parent | 1530487cb1edaf8f953dabfd901c4b255a32c950 (diff) | |
| download | bcm5719-llvm-412c362d9ee922585027cedf97002cba5a30a6bc.tar.gz bcm5719-llvm-412c362d9ee922585027cedf97002cba5a30a6bc.zip | |
When performing name lookup for a namespace definition, only look into
the current context's redeclaration context, ignoring using
directives. Fixes PR8430.
llvm-svn: 117097
| -rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 20 | ||||
| -rw-r--r-- | clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp | 24 |
2 files changed, 35 insertions, 9 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 2f3b2f4262e..564dab49de8 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -3216,15 +3216,17 @@ Decl *Sema::ActOnStartNamespaceDef(Scope *NamespcScope, if (II) { // C++ [namespace.def]p2: - // The identifier in an original-namespace-definition shall not have been - // previously defined in the declarative region in which the - // original-namespace-definition appears. The identifier in an - // original-namespace-definition is the name of the namespace. Subsequently - // in that declarative region, it is treated as an original-namespace-name. - - NamedDecl *PrevDecl - = LookupSingleName(DeclRegionScope, II, IdentLoc, LookupOrdinaryName, - ForRedeclaration); + // The identifier in an original-namespace-definition shall not + // have been previously defined in the declarative region in + // which the original-namespace-definition appears. The + // identifier in an original-namespace-definition is the name of + // the namespace. Subsequently in that declarative region, it is + // treated as an original-namespace-name. + // + // Since namespace names are unique in their scope, and we don't + // look through using directives, just + DeclContext::lookup_result R = CurContext->getRedeclContext()->lookup(II); + NamedDecl *PrevDecl = R.first == R.second? 0 : *R.first; if (NamespaceDecl *OrigNS = dyn_cast_or_null<NamespaceDecl>(PrevDecl)) { // This is an extended namespace definition. diff --git a/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp new file mode 100644 index 00000000000..411c16cd8df --- /dev/null +++ b/clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// PR8430 +namespace N { + class A { }; +} + +namespace M { } + +using namespace M; + +namespace N { + namespace M { + } +} + +namespace M { + namespace N { + } +} + +namespace N { + A *getA(); +} |

