diff --git a/lib/Utils/AST.cpp b/lib/Utils/AST.cpp index 29505895b2..54dad90487 100644 --- a/lib/Utils/AST.cpp +++ b/lib/Utils/AST.cpp @@ -1501,7 +1501,15 @@ namespace utils { // No definition, no lookup result. return; } - S->LookupQualifiedName(R, const_cast(primaryWithin)); + bool res = + S->LookupQualifiedName(R, const_cast(primaryWithin)); + + // If the lookup fails and the context is a namespace, try to lookup in + // the namespaces by setting NotForRedeclaration. + if (!res && primaryWithin->isNamespace()) { + R.setRedeclarationKind(Sema::NotForRedeclaration); + S->LookupQualifiedName(R, const_cast(primaryWithin)); + } } } diff --git a/test/.clang-format b/test/.clang-format new file mode 100644 index 0000000000..e3845288a2 --- /dev/null +++ b/test/.clang-format @@ -0,0 +1 @@ +DisableFormat: true diff --git a/test/Lookup/named.C b/test/Lookup/named.C index 2462d30bbc..cc18419fe2 100644 --- a/test/Lookup/named.C +++ b/test/Lookup/named.C @@ -37,6 +37,13 @@ namespace AnotherNext { class Inside_AnotherNext {}; } +namespace A { + class C; +} +namespace B { + using namespace A; +} + .rawInput 0 // ROOT-6095: names introduced in a scopeless enum should be available in the @@ -106,3 +113,20 @@ decl decl = utils::Lookup::Named(&S, "EvenLess", context); decl //CHECK: (const clang::NamedDecl *) {{0x0*$|nullptr}} + +// Lookup the declaration for namespace B. +decl = utils::Lookup::Named(&S, "B", nullptr); +decl +// CHECK: (const clang::NamedDecl *) 0x{{[1-9a-f][0-9a-f]*$}} + +const clang::DeclContext* contextB = llvm::dyn_cast(decl); +contextB +// CHECK: (const clang::DeclContext *) 0x{{[1-9a-f][0-9a-f]*$}} + +// Lookup 'C' from namespace B. +decl = utils::Lookup::Named(&S, "C", contextB); +decl +// CHECK: (const clang::NamedDecl *) 0x{{[1-9a-f][0-9a-f]*$}} + +decl->getQualifiedNameAsString() +// CHECK: (std::string) "A::C"