From c30873fa8abdd2acfeba6091c1e6e7b5a05a30fd Mon Sep 17 00:00:00 2001 From: Devajith Valaparambil Sreeramaswamy Date: Wed, 8 May 2024 18:00:19 +0200 Subject: [PATCH] Make cling::utils::Lookup::Named look into using directives --- lib/Utils/AST.cpp | 10 +++++++++- test/.clang-format | 1 + test/Lookup/named.C | 24 ++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 test/.clang-format 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"