Skip to content

Commit

Permalink
[cling] Make cling::utils::Lookup::Named look into using directives
Browse files Browse the repository at this point in the history
  • Loading branch information
devajithvs committed May 10, 2024
1 parent 37f978c commit 3e51aa5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
10 changes: 9 additions & 1 deletion interpreter/cling/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->LookupName(R, S->TUScope);
}
}
}

Expand Down
26 changes: 26 additions & 0 deletions interpreter/cling/test/Lookup/named.C
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// LICENSE.TXT for details.
//------------------------------------------------------------------------------

// clang-format off
// RUN: cat %s | %cling -fno-rtti 2>&1 | FileCheck %s
// Test Lookup::Named and Namespace, used in quick simple lookups.

Expand Down Expand Up @@ -37,6 +38,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 +114,21 @@ 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 3e51aa5

Please sign in to comment.