Skip to content

Commit

Permalink
Make cling::utils::Lookup::Named look into using directives
Browse files Browse the repository at this point in the history
  • Loading branch information
devajithvs authored and jenkins committed Sep 26, 2024
1 parent dd44212 commit c30873f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/Utils/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,15 @@ namespace utils {
// No definition, no lookup result.
return;
}
S->LookupQualifiedName(R, const_cast<DeclContext*>(primaryWithin));
bool res =
S->LookupQualifiedName(R, const_cast<DeclContext*>(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<DeclContext*>(primaryWithin));
}
}
}

Expand Down
1 change: 1 addition & 0 deletions test/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DisableFormat: true
24 changes: 24 additions & 0 deletions test/Lookup/named.C
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<clang::DeclContext>(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"

0 comments on commit c30873f

Please sign in to comment.