Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cling] Make cling::utils::Lookup::Named look into using directives #15458

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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->LookupQualifiedName(R, const_cast<DeclContext*>(primaryWithin));
}
}
}

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